-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1111.cpp
More file actions
58 lines (54 loc) · 1.34 KB
/
1111.cpp
File metadata and controls
58 lines (54 loc) · 1.34 KB
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
/**
* ____
* ____ ___ ____ ________ __/ __/
* / __ `__ \/ __ `/ ___/ / / / /_
* / / / / / / /_/ / / / /_/ / __/
* /_/ /_/ /_/\__,_/_/ \__,_/_/
*
* @link : https://the-redback.com
*/
#include <bits/stdc++.h>
using namespace std;
#define ppb pop_back
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define inf 1000000000
#define eps 1e-9
#define NN 1011
vector<int> e[NN], arr;
bool viw[NN];
int dis[NN];
queue<int> q;
int dfs(int u) {
viw[u] = 1;
dis[u]++;
for (int i = 0; i < e[u].size(); i++)
if (viw[e[u][i]] == 0) dfs(e[u][i]);
}
int main() {
ios_base::sync_with_stdio(false);
int t = 1, tc;
cin >> tc;
int i, j, k, l, m, n, man;
while (tc--) {
cin >> man >> n >> m;
arr.clear();
for (i = 0; i < man; i++) cin >> k, arr.pb(k);
for (i = 0; i <= n; i++) e[i].clear();
for (i = 0; i < m; i++) {
cin >> k >> l;
e[k].pb(l);
}
mem(dis, 0);
int sum = 0;
for (i = 0; i < man; i++) {
mem(viw, 0);
dfs(arr[i]);
}
for (i = 0; i <= n; i++)
if (dis[i] == man) sum++;
printf("Case %d: %d\n", t++, sum);
}
return 0;
}