結果
問題 | No.1601 With Animals into Institute |
ユーザー |
|
提出日時 | 2022-01-10 21:44:19 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,502 ms / 3,000 ms |
コード長 | 976 bytes |
コンパイル時間 | 275 ms |
コンパイル使用メモリ | 82,044 KB |
実行使用メモリ | 160,664 KB |
最終ジャッジ日時 | 2024-11-14 11:10:20 |
合計ジャッジ時間 | 33,341 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
N,M = map(int,input().split()) G = [[] for _ in range(N+1)] for _ in range(M): a,b,c,x = map(int,input().split()) G[a].append((b,c,x>0)) G[b].append((a,c,x>0)) import heapq q = [] heapq.heapify(q) C = 10 ** 18 dist = [[C] * 2 for _ in range(N+1)] dist[N][0] = 0 heapq.heappush(q,(0,N,False)) while q: d,now,flag = heapq.heappop(q) if flag: if d > dist[now][1]:continue for v,c,x in G[now]: if dist[v][1] > d + c: dist[v][1] = d + c heapq.heappush(q,(d+c,v,True)) else: if d > dist[now][0] or d > dist[now][1]:continue for v,c,x in G[now]: if x: if dist[v][1] > d + c: dist[v][1] = d+c heapq.heappush(q,(d+c,v,True)) else: if dist[v][0] > d + c: dist[v][0] = d + c heapq.heappush(q,(d+c,v,False)) for i in range(1,N): print(dist[i][1])