#include <cstring>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <queue>
#define ll long long
#define PII pair<int, int>
#define PSI pair<string, int>
#define MSI map<string,int>
#define TLE ios::sync_with_stdio(0),cin.tie(0)
#define mod 1000000007
const int INF = 0x3f3f3f3f;
using namespace std;
int a[100005][2] = { 0 };//0 left,1 right;
int main() {
TLE;
int N, M, k, p, head = 1;
cin >> N;
for (int i = 2; i <= N; i++) {
cin >> k >> p;
if (p) {
a[a[k][1]][0] = i;
a[i][0] = k;
a[i][1] = a[k][1];
a[k][1] = i;
}
if (!p) {
if (k == head) head = i;
a[a[k][0]][1] = i;
a[i][1] = k;
a[i][0] = a[k][0];
a[k][0] = i;
}
}
cin >> M;
for (int i = 0; i < M; i++) {
int t; cin >> t;
if (head == t) head = a[t][1];
a[a[t][0]][1] = a[t][1];
a[a[t][1]][0] = a[t][0];
a[t][1] = 0;
a[t][0] = 0;
}
while (head) {
cout << head << " ";
head = a[head][1];
}
cout << endl;
}
数据结构-线性表 (洛谷 P1160 队列安排)
最新推荐文章于 2023-05-25 21:02:29 发布