-
Notifications
You must be signed in to change notification settings - Fork 1
/
uva_11518 Dominos 2.cpp
59 lines (55 loc) · 1.07 KB
/
uva_11518 Dominos 2.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
#include<iostream>
#include<cstdio>
#include<vector>
#define SIZE 10009
using namespace std;
vector < int >vec[SIZE];
bool fall[SIZE];
int nfall;
void dfs(int node)
{
if(!fall[node])
nfall++;
int i;
fall[node]=true;
for(i=0; i<vec[node].size(); i++)
{
int n=vec[node][i];
if(!fall[n])
{
dfs(n);
}
}
}
int main()
{
// freopen("output.txt","w",stdout);
int node,edge,value,n1,n2,tcase,num;
cin>>tcase;
while (tcase--)
{
nfall=0;
cin>>node>>edge>>num;
for(value=0; value<node; value++)
{
fall[value]=false;
vec[value].clear();
}
for(value=0; value<edge; value++)
{
cin>>n1>>n2;
n1--;
n2--;
vec[n1].push_back(n2);
}
for(value=0; value<num; value++)
{
cin>>n1;
n1--;
dfs(n1);
}
cout<<nfall<<endl;
nfall=0;
}
return 0;
}