-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest3.cpp
More file actions
44 lines (32 loc) · 677 Bytes
/
test3.cpp
File metadata and controls
44 lines (32 loc) · 677 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<bits/stdc++.h>
using namespace std;
vector<int>G[1001];
int parent[1001];
bool bonus[1001];
int n, p;
void solve() {
cin >> n >> p;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
parent[i] = x;
}
for (int i = 1; i <= p; i++) {
int x;
cin >> x;
// cerr << x << ": ";
while (parent[x] > 0 && !bonus[parent[x]])
x = parent[x];
// cerr << x << "\n";
bonus[x] = true;
}
for (int i = 1; i <= n; i++)
if (!bonus[i])
cout << i << " ";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}