結果
| 問題 | No.1301 Strange Graph Shortest Path |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-27 00:50:10 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,240 bytes |
| 記録 | |
| コンパイル時間 | 249 ms |
| コンパイル使用メモリ | 84,968 KB |
| 実行使用メモリ | 304,312 KB |
| 最終ジャッジ日時 | 2026-05-05 23:15:32 |
| 合計ジャッジ時間 | 75,860 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 28 WA * 5 |
ソースコード
from heapq import heappop, heappush
N, M = map(int, input().split())
graph = [[] for _ in range(N)]
pos = {}
for _ in range(M):
a, b, c, d = map(int, input().split())
a -= 1; b -= 1
pos[a, b, c] = len(graph[a])
pos[b, a, c] = len(graph[b])
graph[a].append([b, c])
graph[b].append([a, c])
pos[a, b, d] = len(graph[a])
pos[b, a, d] = len(graph[b])
graph[a].append([b, d])
graph[b].append([a, d])
D = [[-1, None, None] for _ in range(N)]
hq = [(0, 0, None, None)]
while hq:
d, node, par, c = heappop(hq)
if D[node][0] != -1:
continue
D[node] = [d, par, c]
for nex, c in graph[node]:
if D[nex][0] == -1:
heappush(hq, (D[node][0]+c, nex, node, c))
INF = 10**10
ans = D[N-1][0]
now = N-1
while now:
_, par, c = D[now]
i1 = pos[par, now, c]
i2 = pos[now, par, c]
graph[par][i1][1] = graph[now][i2][1] = INF
now = par
D = [[-1, None, None] for _ in range(N)]
hq = [(0, N-1, None, None)]
while hq:
d, node, par, c = heappop(hq)
if D[node][0] != -1:
continue
D[node] = [d, par, c]
for nex, c in graph[node]:
if D[nex][0] == -1:
heappush(hq, (D[node][0]+c, nex, node, c))
print(D[0][0]+ans)