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
'Algorithm > Baekjoon' 카테고리의 다른 글
BOJ 11404 플로이드 Python3 - 플로이드 워셜 알고리즘 (0) | 2023.07.15 |
---|---|
BOJ 1753 최단경로 Python3 - 다익스트라 알고리즘 (0) | 2023.07.15 |
BOJ 13458 시험 감독 Python3 (0) | 2023.07.03 |
BOJ 1463 1로 만들기 Python3 (0) | 2023.06.28 |
BOJ 12100 2048 (Easy) Python3 (0) | 2023.06.27 |