from collections import deque
def solution(n, edge):
answer = 0
# 간선과 노드 정보 graph에 저장
graph= [[] for _ in range(n+1)]
for e in edge:
n1, n2 = e[0], e[1]
graph[n1].append(n2)
graph[n2].append(n1)
#print(graph)
# BFS 로직
queue = deque([1])
distance = [-1]*(n+1)
distance[1] = 0 #출발 시작 노드 0
while queue:
curr_node = queue.popleft()
connect_edge = graph[curr_node]
#print(connect_edge)
for e in connect_edge:
#print(f"{e} 입니다.")
if distance[e] == -1: #방문한 적 없는 경우
queue.append(e)
distance[e] = distance[curr_node] + 1
#print(distance) // [-1, 0, 1, 1, 2, 2, 2]
max_dist = max(distance)
for i in distance:
if i == max_dist:
answer +=1
return answer
📌 느낀 점