Skip to content

Instantly share code, notes, and snippets.

@nafis00141
Created October 10, 2016 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nafis00141/7cb71c4bb1c48dd7ad48d6d686a4ff10 to your computer and use it in GitHub Desktop.
Save nafis00141/7cb71c4bb1c48dd7ad48d6d686a4ff10 to your computer and use it in GitHub Desktop.
#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