-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1043.cpp
64 lines (60 loc) · 1.34 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
//
// Created by kdongha on 2020/01/07.
//
#include <bits/stdc++.h>
int N, M, ans;
bool person[51];
int party[51][51];
bool check[51];
std::queue<int> q;
void solve() {
std::cin >> N >> M;
int p;
std::cin >> p;
for (int i = 0; i < p; i++) {
int temp;
std::cin >> temp;
person[temp] = true;
q.push(temp);
}
for (int i = 0; i < M; i++) {
std::cin >> party[i][0];
for (int j = 1; j <= party[i][0]; j++) {
std::cin >> party[i][j];
}
}
bool flag = true;
while (flag) {
flag = false;
for (int i = 0; i < M; i++) {
if (!check[i]) {
for (int j = 1; j <= party[i][0]; j++) {
if (person[party[i][j]]) {
check[i] = true;
flag = true;
break;
}
}
if (check[i]) {
for (int j = 1; j <= party[i][0]; j++) {
person[party[i][j]] = true;
}
}
}
}
}
ans=0;
for(int i=0;i<M;i++){
if(!check[i]){
ans++;
}
}
std::cout << ans;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
solve();
return 0;
}