[BOJ] 1043 거짓말

Time Lapse :14min 11sec

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
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
bool truth[51];
bool v[51];
vector<int> participate[51];
vector<int> day[51];
queue<int> q;
int n, m, ans, temp, num;
int main() {
scanf("%d %d %d",&n,&m, &temp);
for(int i = 0; i < temp; i++) {
scanf("%d", &num);
q.push(num);
v[num] = true;
}
for(int i = 0; i < m; i++) {
scanf("%d",&temp);
for(int j = 0; j < temp; j++) {
scanf("%d",&num);
day[i].push_back(num);
participate[num].push_back(i);
}
}
while(!q.empty()) {
int val = q.front();
q.pop();
for(auto party : participate[val]) {
if(truth[party]) continue;
for(auto person : day[party]) {
if(v[person]) continue;
v[person] = true;
q.push(person);
}
truth[party] = true;
}
}
for(int i = 0; i < m; i++)
if(!truth[i]) ++ans;
printf("%d",ans);
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/09/07/PS/BOJ/1043/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.