바이러스 [2606] with 파이썬 본문
728x90
https://www.acmicpc.net/problem/2606
2606번: 바이러스
첫째 줄에는 컴퓨터의 수가 주어진다. 컴퓨터의 수는 100 이하이고 각 컴퓨터에는 1번 부터 차례대로 번호가 매겨진다. 둘째 줄에는 네트워크 상에서 직접 연결되어 있는 컴퓨터 쌍의 수가 주어��
www.acmicpc.net
n = int(input())
m = int(input())
adj = [[] for _ in range(n+1)]
visited = [False] * (n+1)
cnt = 0
for _ in range(m):
x, y = map(int, input().split())
adj[x].append(y)
adj[y].append(x)
def dfs(now_pos):
global cnt
cnt += 1
visited[now_pos] = True
for next_pos in adj[now_pos]:
if not visited[next_pos]:
dfs(next_pos)
dfs(1)
# 시작 정점 빼야됨
print(cnt - 1)
'Algorithms > BFS and DFS' 카테고리의 다른 글
Mooyo Mooyo [16768] with 파이썬 (0) | 2020.06.04 |
---|---|
과외맨 [5213] with 파이썬 (0) | 2020.06.02 |
벽 부수고 이동하기 [2206] with 파이썬 (0) | 2020.06.02 |
탈출 [3055] with 파이썬 (0) | 2020.06.02 |
효율적인 해킹 [1325] with 파이썬 (0) | 2020.06.01 |
Comments