백준 2606 - 바이러스 (Python)
링크
https://www.acmicpc.net/problem/2606
전체 소스 코드
def bfs(start_node): q = [] q.append(start_node) check[start_node] = True count = 0
while q: node = q.pop(0)
for i in range(1, node_num+1): if check[i] == False and field[node][i] == 1: q.append(i) count += 1 check[i] = True
return count
node_num = int(input()) line_num = int(input())
field = [[0]*(node_num+1)for i in range(node_num+1)] check = [False]*(node_num+1)
for i in range(line_num): a, b = map(int, input().split()) field[a][b] = 1 field[b][a] = 1
print(bfs(1))
|