노트

[백준] 2606번 바이러스 python 본문

알고리즘

[백준] 2606번 바이러스 python

_Myway 2023. 7. 9. 21:05
v = int(input())
e = int(input())
graph = [[] for _ in range(v+1)]
for _ in range(e):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

def dfs(x):
    global count
    visited[x] = True
    count += 1
    for node in graph[x]:
        if visited[node]:
            continue
        dfs(node)

count = 0
visited = [False for _ in range(v+1)]
dfs(1)
print(count-1)

Comments