반응형
https://www.acmicpc.net/problem/2606
import collections
n = int(input())
link = int(input())
table = collections.defaultdict(list)
for i in range(link):
a, b = map(int, input().split())
table[a].append(b)
table[b].append(a)
discovered=[]
def dfs(computer):
for other in table[computer]:
if other not in discovered:
discovered.append(other)
dfs(other)
dfs(1)
print(len(discovered)-1)
DFS로 쉽게 풀 수 있는 문제!!
댓글