-
Notifications
You must be signed in to change notification settings - Fork 0
/
1043.cpp
67 lines (64 loc) · 1.3 KB
/
1043.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
#include <iostream>
#include <vector>
using namespace std;
int n,m,k;
vector<int> know_people;
vector<int> party[50];
int disjoint[51];
int Find(int x){
if(disjoint[x] == x){
return x;
}
return disjoint[x] = Find(disjoint[x]);
}
void Union(int x, int y){
x = Find(x);
y = Find(y);
disjoint[x] = y;
}
int main(void){
cin >> n >> m;
cin >> k;
for(int i=0; i<k; i++){
int know;
cin >> know;
know_people.push_back(know);
}
for(int i=1; i<=n; i++){
disjoint[i] = i;
}
for(int i=0; i<m; i++){
int p;
cin >> p;
int topTmp;
for(int j=0; j<p; j++){
int num;
cin >> num;
if(j>=1){
Union(num, topTmp);
}
else{
topTmp = num;
}
party[i].push_back(num);
}
}
int ans = m;
for(int i=0; i<m; i++){
bool flag = false;
for(auto& people: party[i]){
for(auto& knowPeople: know_people){
if(Find(people) == Find(knowPeople)){
flag = true;
break;
}
}
if(flag){
ans--;
break;
}
}
}
cout << ans;
return 0;
}