forked from tony9402/baekjoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
65 lines (54 loc) · 1.3 KB
/
main.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
// Authored by : xhdxhl
// Co-authored by : -
// Link : http://boj.kr/d4f08f292aed46729e98bea45c026da6
#include <bits/stdc++.h>
using namespace std;
int n, m, k, parent[51];
vector<int> know;
vector <vector<int>> v(51);
int find(int x) {
if (parent[x] == x) return x;
return parent[x] = find(parent[x]);
}
void merge(int x, int y) {
x = find(x);
y = find(y);
parent[x] = y;
}
int main(void) {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> n >> m >> k;
while (k--) {
int t;
cin >> t;
know.push_back(t);
}
for (int i = 1; i <= n; i++) parent[i] = i;
for (int i = 0; i < m; i++) {
int p, num, prev;
cin >> p;
for (int j = 0; j < p; j++) {
if (j >= 1) {
prev = num;
cin >> num;
merge(prev, num);
}
else cin >> num;
v[i].push_back(num);
}
}
for (auto& list : v) {
bool flag = false;
for (auto& person : list) {
for (auto& t : know) {
if (find(person) == find(t)) {
flag = true;
break;
}
}
if (flag) break;
}
if(flag) m--;
}
cout << m;
}