結果

問題 No.1301 Strange Graph Shortest Path
ユーザー zkouzkou
提出日時 2020-11-04 23:14:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,198 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 73,472 KB
最終ジャッジ日時 2023-10-10 21:34:55
合計ジャッジ時間 31,617 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,176 KB
testcase_01 AC 16 ms
8,224 KB
testcase_02 WA -
testcase_03 AC 698 ms
49,272 KB
testcase_04 AC 1,088 ms
70,256 KB
testcase_05 AC 698 ms
58,156 KB
testcase_06 AC 961 ms
64,336 KB
testcase_07 AC 864 ms
59,520 KB
testcase_08 AC 684 ms
49,640 KB
testcase_09 AC 918 ms
57,864 KB
testcase_10 WA -
testcase_11 AC 990 ms
64,052 KB
testcase_12 AC 970 ms
65,888 KB
testcase_13 AC 841 ms
59,844 KB
testcase_14 AC 865 ms
55,256 KB
testcase_15 AC 868 ms
58,856 KB
testcase_16 AC 1,091 ms
71,228 KB
testcase_17 AC 904 ms
61,700 KB
testcase_18 AC 802 ms
57,516 KB
testcase_19 AC 962 ms
65,512 KB
testcase_20 AC 991 ms
67,728 KB
testcase_21 AC 903 ms
60,696 KB
testcase_22 AC 1,077 ms
69,540 KB
testcase_23 AC 1,033 ms
60,752 KB
testcase_24 AC 982 ms
67,068 KB
testcase_25 AC 1,077 ms
67,732 KB
testcase_26 AC 918 ms
61,216 KB
testcase_27 AC 920 ms
63,220 KB
testcase_28 AC 706 ms
57,120 KB
testcase_29 WA -
testcase_30 AC 1,005 ms
66,196 KB
testcase_31 AC 1,081 ms
68,228 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 984 ms
63,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from heapq import * 

input = sys.stdin.readline

INF = float("inf")

N, M = map(int, input().split())
adj = [dict() for _ in range(N)]
uv2d = dict()
for _ in range(M):
    u, v, c, d = map(int, input().split())
    u -= 1
    v -= 1
    adj[u][v] = adj[v][u] = c
    uv2d[(u, v)] = uv2d[(v, u)] = d

# pq が持つのは、(コスト, 頂点)
# dijkstra 1回目
pq = [(0, 0)]
dp = [INF] * N
dp[0] = 0
parent = [-1] * N
while pq:
    cost, v = heappop(pq)
    if cost > dp[v]:
        continue
    for nv, dist in adj[v].items():
        if dp[nv] > dp[v] + dist:
            dp[nv] = dp[v] + dist
            parent[nv] = v
            heappush(pq, (dp[nv], nv))
# print(dp)
v = N - 1
while v != 0:
    p = parent[v]
    adj[v][p] = adj[p][v] = uv2d[(v, p)]
    v = p

# pq が持つのは、(コスト, 頂点)
# dijkstra 2回目
pq = [(dp[N - 1], N - 1)]
for i in range(N - 1):
    dp[i] = INF
# parent = [-1] * N
while pq:
    cost, v = heappop(pq)
    if cost > dp[v]:
        continue
    for nv, dist in adj[v].items():
        if dp[nv] > dp[v] + dist:
            dp[nv] = dp[v] + dist
            # parent[nv] = v
            heappush(pq, (dp[nv], nv))
# print(dp)
print(dp[0])
0