[BOJ] 2606 바이러스

Time Lapse :6min 27sec

2606.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
int conn[101][101], virus[101], q[100];
int N, line, f, e, v, ans, i;
int main(void) {
scanf("%d %d",&N, &line);
q[0] = virus[1] = 1;
for(i = 0;i < line; ++i){
scanf("%d %d",&f,&e);
conn[f][e] = conn[e][f] = 1;
}
f = 0; e = 1;
while(f^e){
v = q[f++];
for(i = 2; i <= N; ++i)
if(!virus[i]&&conn[v][i])
virus[i] = q[e++] = i, ++ans;
}
printf("%d",ans);
return 0;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/2606/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.