문제 출처
풀이
N, M = map(int, input().split())
cabins = [[] for _ in range(N+1)]
for _ in range(M):
a, b = map(int, input().split())
cabins[a].append(b)
cabins[b].append(a)
visited = [0] * (N+1)
d, now = 0, [1]
visited[1] = 1
while 1:
nxt = []
for i in now:
for j in cabins[i]:
if visited[j]:
continue
nxt.append(j)
visited[j] = 1
if nxt:
now = nxt
d += 1
else:
print(min(now), d, len(now))
break
'백준' 카테고리의 다른 글
[python] 13549. 숨바꼭질 3 (0) | 2019.08.19 |
---|---|
[python] 12851. 숨바꼭질 2 (0) | 2019.08.19 |
[python] 13023. ABCDE (0) | 2019.08.19 |
[python] 2916. 자와 각도기 (0) | 2019.08.08 |
[python] 1904. 01타일 (0) | 2019.08.08 |