Created
October 10, 2016 06:04
-
-
Save nafis00141/7cb71c4bb1c48dd7ad48d6d686a4ff10 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
vector<int>V[10005]; | |
bool visited[10005]; | |
void dfs(int a){ | |
visited[a]=true; | |
for(int i=0;i<V[a].size();i++){ | |
int b =V[a][i]; | |
if(visited[b]==false){ | |
dfs(b); | |
} | |
} | |
} | |
void Vclear(){ | |
for(int i=0;i<10005;i++){ | |
V[i].clear(); | |
visited[i]=false; | |
} | |
} | |
int main(){ | |
int t; | |
cin>>t; | |
for(int k=0;k<t;k++){ | |
Vclear(); | |
int n,m,l; | |
cin>>n>>m>>l; | |
for(int j=0;j<m;j++){ | |
int a,b; | |
cin>>a>>b; | |
V[a].push_back(b); | |
} | |
for(int j=0;j<l;j++){ | |
int a; | |
cin>>a; | |
dfs(a); | |
} | |
int cou=0; | |
for(int j=1;j<=n;j++){ | |
if(visited[j]==true) cou++; | |
} | |
cout<<cou<<"\n"; | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment