-
Notifications
You must be signed in to change notification settings - Fork 0
/
11518.cpp
68 lines (64 loc) · 1.03 KB
/
11518.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
/*
11518 - Dominos 2
*/
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> v;
typedef vector<v> vv;
void dfs(const vv&mat, v&vis, int node)
{
if(vis[node])
return;
vis[node]=1;
for(int i=mat[node].size()-1; i>=0; i--)
{
int v = mat[node][i];
if(vis[v]==0)
{
dfs(mat,vis,v);
}
}
}
int main()
{
///freopen("input.txt", "r", stdin);
///freopen("output.txt", "w", stdout);
int t,n,m,l,x,y;
cin>>t;
while(t--)
{
cin>>n>>m>>l;
vv mat(n+1);
v vis(n+1,false);
for(int i=0; i<m; i++)
{
cin>>x>>y;
mat[x].push_back(y);
}
int cnt=0;
for(int i=0; i<l; i++)
{
cin>>x;
if(vis[x]==0)
{
dfs(mat,vis,x);
}
}
for(int i=1; i<=n; i++)
{
cnt+=vis[i];
}
cout<<cnt<<endl;
}
return 0;
}
/*
Sample Input
1
3 2 1
1 2
2 3
2
Sample Output
2
*/