結果
| 問題 | No.614 壊れたキャンパス | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-04-25 09:29:59 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                TLE
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 1,444 bytes | 
| コンパイル時間 | 312 ms | 
| コンパイル使用メモリ | 82,496 KB | 
| 実行使用メモリ | 280,108 KB | 
| 最終ジャッジ日時 | 2024-06-27 05:02:15 | 
| 合計ジャッジ時間 | 21,119 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 19 TLE * 1 | 
ソースコード
import sys
from heapq import heappop, heappush
input = sys.stdin.buffer.readline
INF = 10 ** 18
def dijkstra(N, G, s):
    dist = [INF] * N
    que = [(0, s)]
    dist[s] = 0
    while que:
        c, v = heappop(que)
        if dist[v] < c:
            continue
        for t, cost in G[v]:
            if dist[v] + cost < dist[t]:
                dist[t] = dist[v] + cost
                heappush(que, (dist[t], t))
    return dist
N, M, K, S, T = map(int, input().split())
S -= 1
T -= 1
passages = tuple(tuple(int(x) - 1 for x in input().split()) for _ in range(M))
node_S = (0, S)
node_T = (N - 1, T)
node_set = {node_S, node_T}
for a, b, c in passages:
    node_set.add((a, b))
    node_set.add((a + 1, c))
node_dict = {t: i for i, t in enumerate(node_set)}
L = len(node_set)
G = [[] for _ in range(L)]
def add_edge(s_bldg, s_floor, t_bldg, t_floor, cost):
    s = node_dict[(s_bldg, s_floor)]
    t = node_dict[(t_bldg, t_floor)]
    G[s].append((t, cost))
for a, b, c in passages:
    add_edge(a, b, a + 1, c, 0)
towers = [[] for _ in range(N)]
for a, b in node_set:
    towers[a].append(b)
for i in range(N):
    towers[i].sort()
    for j in range(len(towers[i]) - 1):
        f1 = towers[i][j]
        f2 = towers[i][j + 1]
        assert f2 > f1
        add_edge(i, f1, i, f2, f2 - f1)
        add_edge(i, f2, i, f1, f2 - f1)
ans = dijkstra(L, G, node_dict[node_S])[node_dict[node_T]]
print(ans if ans != INF else -1)
            
            
            
        