結果
| 問題 | No.1601 With Animals into Institute |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-10 21:44:19 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 1,641 ms / 3,000 ms |
| コード長 | 976 bytes |
| 記録 | |
| コンパイル時間 | 476 ms |
| コンパイル使用メモリ | 84,864 KB |
| 実行使用メモリ | 164,376 KB |
| 最終ジャッジ日時 | 2026-05-09 23:24:35 |
| 合計ジャッジ時間 | 22,858 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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])