結果

問題 No.1473 おでぶなおばけさん
ユーザー lloyz
提出日時 2022-08-11 21:47:18
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 646 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 82,592 KB
実行使用メモリ 249,844 KB
最終ジャッジ日時 2024-09-22 04:56:33
合計ジャッジ時間 6,543 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 1 TLE * 1 -- * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappop, heappush
from collections import defaultdict

n, m = map(int, input().split())
edge = defaultdict(list)
for _ in range(m):
    s, t, d = map(int, input().split())
    edge[s].append((t, d))
    edge[t].append((s, d))

for i in range(1, n + 1):
    edge[i].sort(key=lambda x: -x[1])

H = [(-10**18, 0, 1)]
seen = set((1, 10**18))
heapify(H)
while H:
    w, cnt, cp = heappop(H)
    w *= -1
    if cp == n:
        print(w, cnt)
        break
    for np, nw in edge[cp]:
        nw = min(nw, w)
        if (np, nw) in seen:
            continue
        seen.add((np, nw))
        heappush(H, (-nw, cnt + 1, np))
0