-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11518.cpp
More file actions
56 lines (52 loc) · 770 Bytes
/
11518.cpp
File metadata and controls
56 lines (52 loc) · 770 Bytes
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
#include<bits/stdc++.h>
using namespace std;
map<int,vector<int> >G;
map<int,bool>visited;
void dfs(int y){
for(auto i:G[y]){
if(visited[i] == false){
visited[i] = true;
dfs(i);
}
}
}
int main(){
int t;
cin>>t;
cin.ignore();
while(t--){
string s;
stringstream ss;
getline(cin,s);
ss<<s;
int n,m,l;
ss>>n>>m>>l;
for(int i=1;i<=n;i++){
visited[i] = false;
}
ss.clear();
int a,b;
while(m--){
getline(cin,s);
ss<<s;
ss>>a>>b;
G[a].push_back(b);
ss.clear();
}
int x;
while(l--){
cin>>x;
visited[x] = true;
dfs(x);
cin.ignore();
}
int cnt = 0;
for(int i = 1;i<=n;i++){
if(visited[i] == true){
cnt++;
}
}
cout<< cnt <<endl;
G.clear();
}
}