반응형 가장 먼 노드 파이썬1 [파이썬🐍] 프로그래머스 : 가장 먼 노드 from collections import deque def solution(n, edge): def bfs(): q = deque() q.append(1) while q: x = q.popleft() for i in a[x]: if ch[i] == 0: ch[i] = ch[x] + 1 q.append(i) a = [[] for i in range(n+1)] ch = [0]*(n+1) for i,j in edge: a[i].append(j) a[j].append(i) ch[1] = 1 bfs() return ch.count(max(ch)) 2021. 6. 30. 이전 1 다음 반응형