結果
| 問題 |
No.1301 Strange Graph Shortest Path
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-11-27 23:38:44 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,261 bytes |
| コンパイル時間 | 266 ms |
| コンパイル使用メモリ | 82,460 KB |
| 実行使用メモリ | 272,432 KB |
| 最終ジャッジ日時 | 2024-09-13 01:17:08 |
| 合計ジャッジ時間 | 57,344 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 WA * 5 |
ソースコード
from copy import deepcopy
from collections import deque
n,m = map(int,input().split())
e = [[] for i in range(n)]
for i in range(m):
u,v,c,d = map(int,input().split())
u -= 1
v -= 1
e[u].append([v,c,d])
e[v].append([u,c,d])
def search(a,b,g):
dis = [10**20]*n
dis[a] = 0
par = [-1]*n
q = deque([a])
while q:
now = q.popleft()
for nex,c,d in g[now]:
if dis[nex] > dis[now]+c:
dis[nex] = dis[now]+c
par[nex] = now
q.append(nex)
ans = dis[b]
now = b
while par[now] != -1:
p = par[now]
for i in range(len(g[now])):
if g[now][i][0] == p:
g[now][i][1] = -1
break
now = p
dis = [10**20]*n
dis[b] = 0
q = deque([b])
while q:
now = q.popleft()
for nex,c,d in g[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[a]
return ans
print(min(search(0,n-1,deepcopy(e)),search(n-1,0,deepcopy(e))))