#include <bits/stdc++.h>
#define S 10003
using namespace std;
vector <int> Dominos[S];
int vis[S], cn;
int dfs(int src){
if(vis[src])return 0;
vis[src] = 1;
cn++;
int sz = Dominos[src].size();
for(int z = 0; z < sz; z++){
int u = Dominos[src][z];
dfs(u);
}
return cn;
}
int main(){
int t, n, m, l, x, y, z;
cin >> t;
while(t--){
cin >> n >> m >> l;
for(int i = 0; i < m; i++){
cin >> x >> y;
Dominos[x].push_back(y);
}
memset(vis, 0, sizeof(vis));
int ans = 0;
for(int i = 0; i < l; i++){
cn = 0;
cin >> z;
dfs(z);
ans += cn;
}
cout << ans << endl;
for(int i = 0; i <= n; i++)Dominos[i].clear();
}
return 0;
}
#define S 10003
using namespace std;
vector <int> Dominos[S];
int vis[S], cn;
int dfs(int src){
if(vis[src])return 0;
vis[src] = 1;
cn++;
int sz = Dominos[src].size();
for(int z = 0; z < sz; z++){
int u = Dominos[src][z];
dfs(u);
}
return cn;
}
int main(){
int t, n, m, l, x, y, z;
cin >> t;
while(t--){
cin >> n >> m >> l;
for(int i = 0; i < m; i++){
cin >> x >> y;
Dominos[x].push_back(y);
}
memset(vis, 0, sizeof(vis));
int ans = 0;
for(int i = 0; i < l; i++){
cn = 0;
cin >> z;
dfs(z);
ans += cn;
}
cout << ans << endl;
for(int i = 0; i <= n; i++)Dominos[i].clear();
}
return 0;
}
No comments:
Post a Comment