Algorithm/Baekjoon
BOJ 2606 바이러스 Python3
Bonita SY
2023. 7. 6. 20:08
728x90
import sys
input = sys.stdin.readline
computer_cnt = int(input().rstrip())
graph = [[False]*(computer_cnt+1) for _ in range(computer_cnt+1)]
link_cnt = int(input().rstrip())
for _ in range(link_cnt):
x, y = map(int, input().rstrip().split())
graph[x][y] = True
graph[y][x] = True
visited = [1]
result = 0
def dfs(x):
global result
warm_list = []
for i in range(1, computer_cnt+1):
if graph[x][i] and (i not in visited):
warm_list.append(i)
visited.append(i)
dfs(i)
result += len(warm_list)
dfs(1)
print(result)
https://www.acmicpc.net/problem/2606
2606번: 바이러스
첫째 줄에는 컴퓨터의 수가 주어진다. 컴퓨터의 수는 100 이하인 양의 정수이고 각 컴퓨터에는 1번 부터 차례대로 번호가 매겨진다. 둘째 줄에는 네트워크 상에서 직접 연결되어 있는 컴퓨터 쌍
www.acmicpc.net
728x90