-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj1043.cpp
More file actions
53 lines (46 loc) · 822 Bytes
/
boj1043.cpp
File metadata and controls
53 lines (46 loc) · 822 Bytes
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
#include<iostream>
using namespace std;
int n, m, k, boss[55], cnt = 0;
int Find(int x)
{
if(x == boss[x]) return x;
else return boss[x] = Find(boss[x]);
}
void Union(int x, int y)
{
int X = Find(x);
int Y = Find(y);
if(X == 1 && Y == 0) boss[y] = 1;
if(X == 0 && Y == 1) boss[x] = 1;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k;
for(int i = 0, j; i < k; i++){
cin >> j;
boss[j] = 1;
}
while(m--){
int tmp, party[55] = {}, flag = 0, trueman;
cin >> tmp;
for(int i = 0; i < tmp; i++){
cin >> party[i];
if(boss[party[i]] == 1){
flag = 1;
trueman = party[i];
}
}
if(flag == 1){
for(int i = 0; party[i] != 0; i++){
if(party[i] == trueman) continue;
Union(trueman,party[i]);
}
}
else{
cnt++;
}
}
printf("%d", cnt);
}