Skip to content

Commit 7b29a9f

Browse files
committed
[BOJ] 바이러스 / 실버3 / 25분
https://www.acmicpc.net/problem/2606
1 parent 5c57fef commit 7b29a9f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from collections import defaultdict
2+
from collections import deque
3+
4+
5+
def bfs(graph, visited):
6+
queue = deque()
7+
8+
queue.append(1)
9+
visited[1] = 1
10+
answer = 0
11+
12+
while queue:
13+
num = queue.popleft()
14+
for neighbor in graph[num]:
15+
if visited[neighbor] == 0:
16+
queue.append(neighbor)
17+
visited[neighbor] = 1
18+
answer += 1
19+
20+
print(answer)
21+
22+
23+
numOfComputer = int(input())
24+
numOfConnection = int(input())
25+
26+
graph = defaultdict(list)
27+
visited = [0] * (numOfComputer + 1)
28+
29+
for _ in range(numOfConnection):
30+
n1, n2 = map(int, input().split())
31+
graph[n1].append(n2)
32+
graph[n2].append(n1)
33+
34+
bfs(graph, visited)

0 commit comments

Comments
 (0)