結果
問題 |
No.1473 おでぶなおばけさん
|
ユーザー |
|
提出日時 | 2021-04-13 22:34:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 686 ms / 2,000 ms |
コード長 | 1,005 bytes |
コンパイル時間 | 148 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 101,764 KB |
最終ジャッジ日時 | 2024-06-30 01:39:25 |
合計ジャッジ時間 | 19,951 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 47 |
ソースコード
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]: ans[next]=max(cost,e_cost) root[next]=root[node]+1 heappush(open,[max(cost,e_cost),next]) return ans[-1]*-1 border=dijkstra(0,n,edge) from collections import deque que=deque([(0,0)]) visited=[-1]*n while que: node,value=que.popleft() if visited[node]>=0: continue visited[node]=value for next,tmp in edge[node]: if -border>=tmp and visited[next]==-1: que.append((next,value+1)) print(border,visited[-1])