結果

問題 No.1301 Strange Graph Shortest Path
ユーザー nehan_der_thalnehan_der_thal
提出日時 2020-11-27 22:07:40
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,295 bytes
コンパイル時間 933 ms
コンパイル使用メモリ 87,304 KB
実行使用メモリ 165,384 KB
最終ジャッジ日時 2023-10-10 21:42:12
合計ジャッジ時間 28,589 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,656 KB
testcase_01 AC 79 ms
71,300 KB
testcase_02 WA -
testcase_03 AC 656 ms
122,944 KB
testcase_04 AC 950 ms
160,552 KB
testcase_05 AC 629 ms
126,044 KB
testcase_06 AC 863 ms
148,544 KB
testcase_07 AC 792 ms
136,128 KB
testcase_08 AC 673 ms
122,960 KB
testcase_09 AC 829 ms
148,528 KB
testcase_10 WA -
testcase_11 AC 893 ms
147,968 KB
testcase_12 AC 897 ms
150,592 KB
testcase_13 AC 787 ms
131,608 KB
testcase_14 AC 840 ms
142,788 KB
testcase_15 AC 776 ms
137,736 KB
testcase_16 AC 930 ms
161,936 KB
testcase_17 AC 810 ms
137,276 KB
testcase_18 AC 721 ms
131,772 KB
testcase_19 AC 863 ms
150,932 KB
testcase_20 AC 856 ms
156,820 KB
testcase_21 AC 802 ms
137,660 KB
testcase_22 AC 870 ms
160,176 KB
testcase_23 AC 783 ms
134,716 KB
testcase_24 AC 900 ms
156,288 KB
testcase_25 AC 908 ms
154,440 KB
testcase_26 AC 793 ms
141,728 KB
testcase_27 AC 855 ms
146,124 KB
testcase_28 AC 701 ms
125,452 KB
testcase_29 WA -
testcase_30 AC 897 ms
150,312 KB
testcase_31 AC 892 ms
155,224 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 773 ms
150,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop
INF = 10**18
def dijkstra(N, G, s):
    dist = [INF] * N
    parents = [-1]*N
    que = [(0, s)]
    dist[s] = 0
    while que:
        c, v = heappop(que)
        if dist[v] < c:
            continue
        for t, cost in G[v]:
            if dist[v] + cost < dist[t]:
                dist[t] = dist[v] + cost
                parents[t] = v
                heappush(que, (dist[t], t))
    return dist, parents

N, M = map(int, input().split())
G = [set() for _ in range(N)]
vs = list()
X = []
for _ in range(M):
    a, b, c, d = map(int, input().split())
    a-=1;b-=1
    G[a].add((b, c))
    G[b].add((a, c))
    X.append((a, b, c, d))
dd, par = dijkstra(N, G, 0)
ans = dd[N-1]

#c = N-1
#R = [N-1]
#while 1:
#    mn = 10**18
#    rr = -1
#    for u, co in G[c]:
#        if dd[u]+co < mn:
#            mn = co+dd[u]
#            rr = u
#    R.append(rr)
#    c = rr
#    if rr == 0:
#        break

c = N-1
R = [N-1]
while c!=0:
    c = par[c]
    R.append(c)
    
G2 = [set() for _ in range(N)]
vs = set()
for u, v in zip(R, R[1:]):
    vs.add((u, v))
    vs.add((v, u))
for a, b, c, d in X:
    if (a, b) in vs:
        co = d
    else:
        co = c
    G2[a].add((b, co))
    G2[b].add((a, co))

dd, _ = dijkstra(N, G2, N-1)
ans += dd[0]
print(ans)
0