메뉴 건너뛰기

[479] 데이터를 수정해 주세요.

algeo._ 2025.10.18 23:26 조회 수 : 70

import heapq
def dijkstra(start, graph):
    dist = [float('inf')] * len(graph)
    dist[start] = 0
    pq = [(0, start)]
    while pq:
        cur_dist, u = heapq.heappop(pq)
        if dist[u] < cur_dist:
            continue
        for v, cost in graph[u]:
            new_dist = cur_dist + cost
            if new_dist < dist[v]:
                dist[v] = new_dist
                heapq.heappush(pq, (new_dist, v))
    return dist
n, m = map(int, input().split())
bus = [[] for _ in range(n)]
for i in range(m):
    __ = input().split()
    try:
      assert len(__) == 3
    except:
      __ += [input()]
    s, e, c = map(int, __)
    bus[s-1].append([e-1, c])
    bus[e-1].append([s-1, c])
road = dijkstra(0, bus)
print(road[n - 1] if road[n - 1] < 99999999999999999999 else "Impossible")

 

위 코드가 AssertionFailed 이후 EOFError을 받습니다.

즉, 입력 조건에 맞지 않는 데이터가 존재하며, 후행 입력도 존재하지 않아 문제 조건상 마지막 간선의 가중치를 알 수 없는 상황입니다.

수행평가용 문제이고, 문제의 풀이에 치명적인 영향을 주는 문제이기에 가능한 빨리 수정해 주시면 감사하겠습니다.

위로