Skip to content

Commit

Permalink
#21 : 2606_바이러스BFS
Browse files Browse the repository at this point in the history
  • Loading branch information
ziy00n committed May 17, 2023
1 parent 876aa1b commit 4c54f35
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions 이티지윤/2606_바이러스BFS.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys
from collections import deque

N = int(sys.stdin.readline())
C = int(sys.stdin.readline())

graph = [[] for i in range(N+1)]

for i in range(C):
a, b = map(int,sys.stdin.readline().split())
graph[a].append(b)
graph[b].append(a)

visited = []
def bfs(x):
q = deque([x])
visited.append(x)

while q:
v = q.popleft()
for i in graph[v]:
if i not in visited:
q.append(i)
visited.append(i)

bfs(1)
print(len(visited) -1) # 1번 컴퓨터는 제외

0 comments on commit 4c54f35

Please sign in to comment.