-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path280 - vertex.cpp
120 lines (96 loc) · 1.77 KB
/
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*input
3
1 2 0
2 2 0
3 1 2 0
0
2 1 2
0
*/
#include <stdio.h>
#include <cmath>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string.h>
#include <stack>
#include <map>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
using namespace std;
#define r(input) freopen("input.txt","r",stdin)
#define w(output) freopen("output.txt","w",stdout)
#define SSTR( x ) dynamic_cast< std::ostringstream & >( \
( std::ostringstream() << std::dec << x ) ).str()
#define FOR(a , b) for ( int i = a ; i < b ; i++ )
#define FOR2(a , b) for ( int j = a ; j < b ; j++ )
#define sz() size()
#define printArr(array,n) for(int i = 0 ; i < n ; i++) cout << array[i]<<" ";
#define FOREACH(l) for (auto it = l.begin(); it != l.end(); it++)
#define count(i) __builtin_popcount(i)
#define Sort(v) sort(v.begin(),v.end())
#define cover(a,d) memset(a,d,sizeof(a))
#define VISITED 1
#define UNVISITED 0
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
vi visited;
vi adj[105];
void dfs(int u)
{
FOR(0, adj[u].size())
{
int v = adj[u][i];
if ( visited[v] == UNVISITED)
visited[v] = VISITED, dfs(v);
}
}
int main()
{
int n;
cin >> n;
while (true)
{
if ( n == 0)
break;
FOR(0,n)
adj[i].clear();
int i;
cin >> i;
while (i)
{
int j;
cin >> j;
while(j)
{
adj[i-1].push_back(j-1);
cin >> j;
}
cin >> i;
}
int num;
cin >> num;
while (num--)
{
visited.assign(n , UNVISITED);
int u;
cin >> u;
dfs(u-1);
vi sol;
FOR(0, n)
if(visited[i] == UNVISITED)
sol.push_back(i+1);
cout << sol.size();
FOR(0, sol.size())
cout << ' '<< sol[i];
cout << endl;
}
cin >> n;
}
}