문제
나의 풀이
1. 다익스트라 풀이
import heapq
n, m = map(int, input().split())
graph = [[] for _ in range(n + 1)]
INF = int(1e9)
distance = [INF] * (n + 1)
for _ in range(m):
a, b = map(int, input().split())
graph[a].append((b, 1))
graph[b].append((a, 1))
def dijkstra(start):
q = []
heapq.heappush(q, (0, start))
distance[start] = 0
while q:
d, node = heapq.heappop(q)
if distance[node] < d:
continue
for i in graph[node]:
dist = d + i[1]
if dist < distance[i[0]]:
distance[i[0]] = dist
heapq.heappush(q, (dist, i[0]))
for i in range(n + 1):
if distance[i] == INF:
distance[i] = -1
m_d = max(distance)
return distance.index(m_d), m_d, distance.count(m_d)
print(*dijkstra(1))