結果

問題 No.1473 おでぶなおばけさん
ユーザー NoaSaber
提出日時 2021-04-09 23:09:44
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 761 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 121,624 KB
最終ジャッジ日時 2024-06-25 06:58:27
合計ジャッジ時間 17,344 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 10 WA * 8 TLE * 6 -- * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m=map(int,input().split())
edge=[[] for i in range(n)]
for i in range(m):
    s,t,d=map(int,input().split())
    s-=1;t-=1
    edge[s].append((t,d*-1))
    edge[t].append((s,d*-1))
from heapq import heappop,heappush
def dijkstra(s,n,edge):
    inf=float("inf")
    ans=[inf]*n
    ans[s]=0
    root=[0]*n
    open=[[-inf,s]]
    while open:
        cost,node=heappop(open)
        if ans[node]<cost:
            continue
        for next,e_cost in edge[node]:
            if max(cost,e_cost)<ans[next] or (max(cost,e_cost)==ans[next] and root[next]>root[node]+1):
                ans[next]=max(cost,e_cost)
                root[next]=root[node]+1
                heappush(open,[max(cost,e_cost),next])
    return ans[-1]*-1,root[-1]
print(*dijkstra(0,n,edge))
0