結果

問題 No.1301 Strange Graph Shortest Path
ユーザー tktk_snsntktk_snsn
提出日時 2020-11-27 22:53:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,264 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 87,208 KB
実行使用メモリ 102,088 KB
最終ジャッジ日時 2023-10-09 21:47:39
合計ジャッジ時間 24,902 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
71,252 KB
testcase_01 AC 80 ms
71,128 KB
testcase_02 WA -
testcase_03 AC 552 ms
93,392 KB
testcase_04 AC 772 ms
101,632 KB
testcase_05 AC 537 ms
93,668 KB
testcase_06 AC 713 ms
99,224 KB
testcase_07 AC 680 ms
97,548 KB
testcase_08 AC 530 ms
93,440 KB
testcase_09 AC 689 ms
98,136 KB
testcase_10 WA -
testcase_11 AC 779 ms
99,876 KB
testcase_12 AC 721 ms
99,904 KB
testcase_13 AC 656 ms
96,464 KB
testcase_14 AC 748 ms
98,812 KB
testcase_15 AC 705 ms
97,272 KB
testcase_16 AC 789 ms
101,640 KB
testcase_17 AC 718 ms
97,744 KB
testcase_18 AC 684 ms
95,944 KB
testcase_19 AC 777 ms
99,764 KB
testcase_20 AC 717 ms
100,208 KB
testcase_21 AC 672 ms
96,984 KB
testcase_22 AC 746 ms
100,912 KB
testcase_23 AC 693 ms
96,652 KB
testcase_24 AC 766 ms
100,972 KB
testcase_25 AC 757 ms
101,416 KB
testcase_26 AC 698 ms
98,196 KB
testcase_27 AC 728 ms
99,376 KB
testcase_28 AC 576 ms
93,776 KB
testcase_29 WA -
testcase_30 AC 803 ms
100,380 KB
testcase_31 AC 793 ms
101,420 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 565 ms
99,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
U = 10 ** 5
inf = 10**18

n, m = map(int, input().split())
edge = [[] for _ in range(n)]
cost = dict()
for _ in range(m):
    a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    if a > b:
        a, b = b, a
    edge[a].append(b)
    edge[b].append(a)
    cost[a * U + b] = (c, d)

dist = [inf] * n
prev = [-1] * n
dist[0] = 0
que = [(0, 0)]
while que:
    ds, s = heapq.heappop(que)
    if dist[s] < ds:
        continue
    for t in edge[s]:
        a, b = min(s, t), max(s, t)
        dt = cost[a * U + b][0]
        if dist[t] > ds + dt:
            dist[t] = ds + dt
            prev[t] = s
            heapq.heappush(que, (ds + dt, t))
ans = dist[n - 1]
s = n - 1
while prev[s] != -1:
    t = prev[s]
    a, b = min(s, t), max(s, t)
    c, d = cost[a * U + b]
    cost[a * U + b] = (d, -1)
    s = t


dist = [inf] * n
dist[n - 1] = 0
que = [(0, n - 1)]
while que:
    ds, s = heapq.heappop(que)
    if dist[s] < ds:
        continue
    for t in edge[s]:
        a, b = min(s, t), max(s, t)
        dt = cost[a * U + b][0]
        if dist[t] > ds + dt:
            dist[t] = ds + dt
            heapq.heappush(que, (ds + dt, t))

ans += dist[0]
print(ans)
0