UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213808#582. t1xuewentaoCompile Error//C++1.1kb2024-11-13 20:13:522024-11-13 23:05:10

answer

#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e5 + 10;

int a[maxn];

int fa[maxn];
vector<int> G[maxn];

int r[maxn];

struct Point{
	int v, w;
};

bool operator > (const Point &a, const Point &b) {
	return a.w > b.w;
}

priority_queue<Point, vector<Point>, greater<Point> > que[maxn];

int n;

void init(int u) {
	r[u] = a[u];
	for (int v: G[u]) {
		init(v);
		r[u] = min(r[u], r[v]);
		que[u].push({v, r[v]});
	}
}

int vis[maxn];

int dfs(int u) {
	if (que[u].size() == 0) {
		vis[u] = 1;
		return u;
	}
	
	int res = dfs(que[u].top().v);
	
	if (vis[que[u].top().v]) {
		que[u].pop();
	} else {
		auto tmp = que[u].top();
		que[u].pop();
		que[u].push({tmp.v, min(a[tmp.v], tmp.w)});
	}
	
	return res;
}

int main() {
	cin >> n;
	for (int i = 2; i <= n; i++) {
		cin >> fa[i];
		G[fa[i]].push_back(i);
	}
	
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	
	init(1);
	
//	for (int i = 1; i <= n; i++) {
//		cout << i << " " << que[i].size() << endl;
//	}
	
	for (int i = 1; i <= n; i++) {
		cout << dfs(1) << " \n"[i==n];
	}
	
}

/*

4
1 2 2
1 3 2 4

*/

详细

answer.code: In function 'void init(int)':
answer.code:28:14: error: range-based 'for' loops are not allowed in C++98 mode
  for (int v: G[u]) {\x0d
              ^
answer.code:31:14: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
   que[u].push({v, r[v]});\x0d
              ^
answer.code:31:24: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
   que[u].push({v, r[v]});\x0d
                    ...