20pts必关求调
查看原帖
20pts必关求调
1259877
TipherethB楼主2024/12/29 15:06
#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> PII;

int n, m, k, p, x, vis[100010];

PII ans[100010];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	ans[1].first = -1;
	ans[1].second = -1;
	for (int i = 2; i <= n; i++) {
		cin >> k >> p;
		if (p) {
			ans[i].first = k;
			ans[i].second = ans[k].second;
			ans[k].second = i;
		} else {
			ans[i].second = k;
			ans[i].first = ans[k].first;
			ans[k].first = i;
		}
	}
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> x;
		vis[x] = 1;
	}
	for (int i = 1; i <= n; i++) {
		if (ans[i].first == -1) {
			while (i != -1) {
				if (!vis[i]) {
					cout << i << ' ';
				}
				i = ans[i].second;
			}
			cout << '\n';
			break;
		}
	}
	return 0;
}
2024/12/29 15:06
加载中...