結果

問題 No.1301 Strange Graph Shortest Path
ユーザー nehan_der_thalnehan_der_thal
提出日時 2020-11-27 21:56:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,382 bytes
コンパイル時間 418 ms
コンパイル使用メモリ 87,092 KB
実行使用メモリ 163,844 KB
最終ジャッジ日時 2023-10-10 21:41:06
合計ジャッジ時間 25,972 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,176 KB
testcase_01 AC 73 ms
71,332 KB
testcase_02 WA -
testcase_03 AC 589 ms
122,812 KB
testcase_04 AC 888 ms
159,292 KB
testcase_05 AC 551 ms
125,824 KB
testcase_06 AC 784 ms
147,788 KB
testcase_07 AC 719 ms
135,700 KB
testcase_08 AC 629 ms
122,740 KB
testcase_09 AC 759 ms
147,180 KB
testcase_10 WA -
testcase_11 AC 807 ms
147,000 KB
testcase_12 AC 819 ms
149,800 KB
testcase_13 AC 695 ms
130,620 KB
testcase_14 AC 721 ms
142,068 KB
testcase_15 AC 678 ms
137,012 KB
testcase_16 AC 834 ms
160,520 KB
testcase_17 AC 707 ms
136,724 KB
testcase_18 AC 662 ms
130,768 KB
testcase_19 AC 774 ms
149,576 KB
testcase_20 AC 813 ms
155,020 KB
testcase_21 AC 692 ms
136,544 KB
testcase_22 AC 764 ms
158,808 KB
testcase_23 AC 686 ms
134,216 KB
testcase_24 AC 792 ms
155,016 KB
testcase_25 AC 836 ms
153,448 KB
testcase_26 AC 704 ms
139,484 KB
testcase_27 AC 754 ms
145,628 KB
testcase_28 AC 601 ms
124,920 KB
testcase_29 WA -
testcase_30 AC 817 ms
149,584 KB
testcase_31 AC 804 ms
153,480 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 762 ms
150,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# V: 頂点数
# g[v] = {(w, cost)}:
#     頂点vから遷移可能な頂点(w)とそのコスト(cost)
# r: 始点の頂点

from heapq import heappush, heappop
INF = 10**18
def dijkstra(N, G, s):
    dist = [INF] * 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
                heappush(que, (dist[t], t))
    return dist

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
#    if a==0:
#        R = min(c+d, R)
#        vs.append((b, c, d))
    G[a].add((b, c))
    G[b].add((a, c))
    X.append((a, b, c, d))
dd = dijkstra(N, G, 0)
ans = dd[N-1]

c = N-1
k = 0
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
    
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:
        G2[a].add((b, d))
        G2[b].add((a, d))
    else:
        G2[a].add((b, c))
        G2[b].add((a, c))

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

print(ans)
0