280 - Vertex

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
int n, i, j, integer, vertex, counter;
bool accessible[101];
vector<int> edge[101];
void DFS(int v) {
int size = edge[v].size(), end;
for (int k = 0; k < size; ++k) {
end = edge[v][k];
if (accessible[end] == false) {
accessible[end] = true;
--counter;
DFS(end);
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
while (cin >> n && n != 0) {
for (int k = 1; k <= n; ++k) {
edge[k].clear();
}
while (cin >> i && i != 0) {
while (cin >> j && j != 0) {
edge[i].push_back(j);
}
}
cin >> integer;
for (int k = 0; k < integer; ++k) {
cin >> vertex;
counter = n;
memset(accessible, false, sizeof(bool) * (n + 1));
DFS(vertex);
cout << counter;
for (int l = 1; l <= n; ++l) {
if (accessible[l] == false) {
cout << ' ' << l;
}
}
cout << '\n';
}
}
return 0;
}