-
Notifications
You must be signed in to change notification settings - Fork 1
/
280 - Vertex.cpp
62 lines (52 loc) · 889 Bytes
/
280 - Vertex.cpp
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
#include<bits/stdc++.h>
using namespace std;
void solve(int n){
vector<int> graph[n+1];
while(1){
int st;
scanf("%d",&st);
if(st==0) break;
while(1){
int x ;
scanf("%d",&x);
if(x==0)
break ;
graph[st].emplace_back(x);
}
}
while(1){
int x;
scanf("%d",&x);
for(int i = 0 ; i < x ; i++){
int stnode;
scanf("%d",&stnode);
bool visited[n+5]={};
stack<int> stk;
stk.push(stnode);
int cnt = 0;
while(!stk.empty()){
int top = stk.top();
stk.pop();
for(auto temp : graph[top]){
if(visited[temp])
continue ;
cnt ++;
visited[temp] = true;
stk.push(temp);
}
}
printf("%d",n-cnt);
for(int t = 1; t <= n ; t++)
if(visited[t]==false)
printf(" %d",t);
puts("");
}
break ;
}
}
int main(){
int n;
while(scanf("%d",&n)==1 and n)
solve(n);
return 0;
}