-
Notifications
You must be signed in to change notification settings - Fork 34
/
1111-Best-Picnic-Ever.cpp
85 lines (66 loc) · 1.12 KB
/
1111-Best-Picnic-Ever.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string.h>
using namespace std;
enum consts { N = 1005};
vector < vector <int> > a;
int n;
int m;
int k;
int city[N];
int vis[N];
int count[N];
int explore(int j, int inc)
{
count[j] += inc;
for (int i = 0; i < a[j].size(); i++) {
int x;
x = a[j][i];
if(vis[x] == 0) {
vis[x] = 1;
explore(x, inc);
}
}
}
int main()
{
int t;
int x;
int y;
int inc;
scanf("%d", &t);
for (int cs = 1; cs <= t; cs++) {
scanf("%d", &k);
scanf("%d", &n);
scanf("%d", &m);
vector < vector <int> > temp(N + 5);
swap(temp, a);
memset(city, 0, sizeof city);
memset(count, 0, sizeof count);
for (int i = 0; i < k; i++) {
scanf("%d", &x);
city[x]++;
}
for (int i = 0; i < m; i++) {
scanf("%d", &x);
scanf("%d", &y);
a[x].push_back(y);
}
for (int i = 1; i <= n; i++) {
memset(vis, 0, sizeof vis);
if(city[i]) {
vis[i] = 1;
inc = city[i];
explore(i, inc);
}
}
int ans;
ans = 0;
for (int i = 1; i <= n; i++) {
if(count[i] >= k)
ans++;
}
printf("Case %d: %d\n", cs, ans);
}
}