-
Notifications
You must be signed in to change notification settings - Fork 0
/
11518.cpp
66 lines (58 loc) · 838 Bytes
/
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
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
#define pb push_back
vector<int> adj[10024];
bool vis[10024];
void flodflil(int o,int& dom){
dom++;
vis[o]=true;
queue<int>q;
q.push(o);
while(!q.empty())
{
int u=q.front();
q.pop();
int tam=adj[u].size();
for(int x=0;x<tam;x++)
{
int px=adj[u][x];
if(!vis[px])
{
vis[px]=true;
dom++;
q.push(px);
}
}
}
}
int main () {
int ct;
cin >> ct;
for(int z=0;z<ct;z++)
{
int n,m,l,c,c2,dom=0,e;
cin >> n >> m >> l;
for(int y=0;y<m;y++)
{
cin >> c >> c2;
adj[c].pb(c2);
}
for(int y=0;y<l;y++)
{
cin >> e;
if(!vis[e])
{
flodflil(e,dom);
}
}
cout << dom << "\n";
memset(vis,false,sizeof(vis));
for(int y=0;y<10024;y++)
{
adj[y].clear();
}
}
}