代码如下:
#include <iostream>
#include <list>
#include <unordered_set>
using namespace std;
struct node
{
int val;
node* next;
node(int val, node* next)
{
this->val = val;
this->next = next;
}
};
unordered_set<int> mamba;
int main()
{
int n;
cin >> n;
node* root = new node(1, nullptr);
node** cur = &root;
node** prev = nullptr;
int index = 1;
n--;
while (n--)
{
int pos, dirt;
cin >> pos >> dirt;
index++;
cur = &root;
if (dirt == 0)
{
node* tail = *cur;
while (tail->val != pos)
{
*prev = tail;
tail = tail->next;
}
if (prev == nullptr)
{
auto now = new node(index, root);
prev = &now;
root = *prev;
}
else
{
(*prev)->next = new node(index, tail);
}
}
else
{
node* tail = *cur;
while (tail->val != pos)
tail = tail->next;
tail->next = new node(index, tail->next);
}
}
int m;
cin >> m;
for (int i = 0; i < m; ++i)
{
int removed;
cin >> removed;
mamba.insert(removed);
}
cur = &root;
while (*cur != nullptr)
{
if (mamba.find((*cur)->val) == mamba.end())
cout << (*cur)->val << " ";
*cur = (*cur)->next;
}
cout << endl;
return 0;
}