結果

問題 No.1301 Strange Graph Shortest Path
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2020-11-27 23:01:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,106 bytes
コンパイル時間 474 ms
コンパイル使用メモリ 86,596 KB
実行使用メモリ 113,292 KB
最終ジャッジ日時 2023-10-09 21:55:52
合計ジャッジ時間 22,465 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,604 KB
testcase_01 AC 95 ms
71,356 KB
testcase_02 WA -
testcase_03 AC 615 ms
102,300 KB
testcase_04 AC 609 ms
109,616 KB
testcase_05 AC 753 ms
101,620 KB
testcase_06 AC 614 ms
106,012 KB
testcase_07 AC 592 ms
103,296 KB
testcase_08 AC 557 ms
99,280 KB
testcase_09 AC 596 ms
107,256 KB
testcase_10 WA -
testcase_11 AC 591 ms
105,916 KB
testcase_12 AC 603 ms
107,344 KB
testcase_13 AC 717 ms
103,896 KB
testcase_14 AC 555 ms
106,544 KB
testcase_15 AC 606 ms
103,788 KB
testcase_16 AC 666 ms
113,132 KB
testcase_17 AC 694 ms
107,000 KB
testcase_18 AC 628 ms
102,336 KB
testcase_19 AC 605 ms
106,704 KB
testcase_20 AC 584 ms
110,140 KB
testcase_21 AC 662 ms
105,444 KB
testcase_22 AC 553 ms
108,792 KB
testcase_23 AC 717 ms
104,540 KB
testcase_24 AC 606 ms
107,616 KB
testcase_25 AC 631 ms
111,080 KB
testcase_26 AC 621 ms
104,564 KB
testcase_27 AC 645 ms
106,112 KB
testcase_28 AC 678 ms
100,912 KB
testcase_29 WA -
testcase_30 AC 665 ms
110,992 KB
testcase_31 AC 688 ms
111,776 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 517 ms
106,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
n,m = map(int,input().split())
e = [[] for i in range(n+1)]
for i in range(m):
    u,v,c,d = map(int,input().split())
    e[u].append([v,c,d])
    e[v].append([u,c,d])
dis = [10**20]*(n+1)
dis[1] = 0
par = [-1]*(n+1)
q = deque([1])
while q:
    now = q.popleft()
    for nex,c,d in e[now]:
        if dis[nex] > dis[now]+c:
            dis[nex] = dis[now]+c
            par[nex] = now
            q.append(nex)
ans = dis[n]
now = n
while par[now] != -1:
    p = par[now]
    for i in range(len(e[now])):
        if e[now][i][0] == p:
            e[now][i][1] = -1
            break
    for i in range(len(e[p])):
        if e[p][i][0] == now:
            e[p][i][1] = -1
            break
    now = p
dis = [10**20]*(n+1)
dis[n] = 0
q = deque([n])
while q:
    now = q.popleft()
    for nex,c,d in e[now]:
        if c == -1:
            if dis[nex] > dis[now]+d:
                dis[nex] = dis[now]+d
                q.append(nex)
        else:
            if dis[nex] > dis[now]+c:
                dis[nex] = dis[now]+c
                q.append(nex)
ans += dis[1]
print(ans)
0