-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6404.cpp
74 lines (69 loc) · 1.35 KB
/
6404.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
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int arr[300005];
int sum=0;
int main()
{
int n,m,k;
cin>>n>>m>>k;
sum=m;
vector<int> input[k];
vector<int> output[k];
for(int i=0;i<m;i++)
{
int a;
cin>>a;
arr[a]=1;
}
for(int i=0;i<k;i++)
{
int a,b;
cin>>a>>b;
for(int j=0;j<a;j++)
{
int c;
cin>>c;
input[i].push_back(c);
}
for(int j=0;j<b;j++)
{
int c;
cin>>c;
output[i].push_back(c);
}
}
bool change=true;
while(change)
{
//cout<<" in while"<<endl;
change=false;
for(int i=0;i<k;i++)
{
bool ok=true;
for(int j=0;j<input[i].size();j++)
{
if(arr[input[i][j]]==0) ok=false;
}
if(ok)
{
for(int j=0;j<output[i].size();j++)
{
if(arr[output[i][j]]==0)
{
change=true;
arr[output[i][j]]=1;
sum++;
}
}
}
}
}
cout<<sum<<endl;
for(int i=0;i<300005;i++)
{
if(arr[i]) cout<<i<<" ";
}
cout<<endl;
return 0;
}