-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathberarii2.cpp
47 lines (46 loc) · 839 Bytes
/
berarii2.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
# include <fstream>
# include <vector>
# include <queue>
# define mil 1000005
using namespace std;
ifstream f("berarii2.in");
ofstream g("berarii2.out");
vector <int> v[mil];
queue <int> q;
int i,j,n,m,x,y,p;
bool bere[mil],ap[mil];
void BFS ()
{
int i,k;
while (! q.empty())
{
k=q.front(); q.pop();
for (i=0; i<v[k].size(); ++i)
{
if (! ap[v[k][i]])
{
ap[v[k][i]]=1; bere[v[k][i]]=1;
q.push(v[k][i]); ++p;
}
}
}
}
int main ()
{
f>>n>>m>>p;
for (i=1; i<=m; ++i)
{
f>>x>>y;
v[y].push_back(x);
}
for (i=1; i<=p; ++i)
{
f>>x;
q.push(x); ap[x]=1; bere[x]=1;
}
BFS ();
g<<n-p<<"\n";
for (i=1; i<=n; ++i)
if (! bere[i]) g<<i<<"\n";
return 0;
}