結果
問題 |
No.1301 Strange Graph Shortest Path
|
ユーザー |
|
提出日時 | 2020-11-27 22:56:59 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 999 bytes |
コンパイル時間 | 506 ms |
コンパイル使用メモリ | 82,268 KB |
実行使用メモリ | 111,504 KB |
最終ジャッジ日時 | 2024-07-26 20:13:11 |
合計ジャッジ時間 | 20,674 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 28 WA * 5 |
ソースコード
from collections import deque n,m = map(int,input().split()) e = [[] for i in range(n+1)] for i in range(m): u,v,c,d = map(int,input().split()) e[u].append([v,c,d]) e[v].append([u,c,d]) dis = [10**20]*(n+1) dis[1] = 0 par = [-1]*(n+1) q = deque([1]) while q: now = q.popleft() for nex,c,d in e[now]: if dis[nex] > dis[now]+c: dis[nex] = dis[now]+c par[nex] = now q.append(nex) ans = dis[n] now = n while par[now] != -1: p = par[now] for i in range(len(e[now])): if e[now][i][0] == p: e[now][i][1] = -1 break now = p dis = [10**20]*(n+1) dis[n] = 0 q = deque([n]) while q: now = q.popleft() for nex,c,d in e[now]: if c == -1: if dis[nex] > dis[now]+d: dis[nex] = dis[now]+d q.append(nex) else: if dis[nex] > dis[now]+c: dis[nex] = dis[now]+c q.append(nex) ans += dis[1] print(ans)