Koala - 14기/코딩테스트 준비 스터디
[백준/python3] 2606번 : 바이러스
יוֹסֵף
2024. 5. 6. 15:36
https://www.acmicpc.net/problem/2606
코드
from collections import deque
n=int(input()) # 컴퓨터 개수
v=int(input()) # 연결선 개수
graph = [[] for i in range(n+1)] # 그래프 초기화
visited=[0]*(n+1) # 방문한 컴퓨터인지 표시
for i in range(v): # 그래프 생성
a,b=map(int,input().split())
graph[a]+=[b]
graph[b]+=[a]
visited[1]=1
Q=deque([1])
while Q:
c=Q.popleft()
for nx in graph[c]:
if visited[nx]==0:
Q.append(nx)
visited[nx]=1
print(sum(visited)-1)