0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 18:56:28 +00:00
OI-codes/Luogu/P1160/P1160.cpp

32 lines
609 B
C++

#include <bits/stdc++.h>
using namespace std;
int n, k, p, m, x, t;
list<int> a;
list<int>::iterator b[100005];
int main() {
cin >> n;
a.push_back(1);
b[1] = a.begin();
for (int i = 2; i <= n; i++) {
cin >> k >> p;
auto it = b[k];
b[i] = a.insert(p ? next(it) : it, i);
}
cin >> m;
for (int i = 1; i <= m; i++) {
cin >> x;
if (b[x] != a.end()) {
a.erase(b[x]);
b[x] = a.end();
}
}
for (auto it = a.begin(); it != a.end(); it++) {
cout << *it << ' ';
}
cout << endl;
return 0;
}