結果

問題 No.1301 Strange Graph Shortest Path
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2020-11-27 23:38:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,261 bytes
コンパイル時間 484 ms
コンパイル使用メモリ 87,192 KB
実行使用メモリ 272,896 KB
最終ジャッジ日時 2023-10-10 21:49:59
合計ジャッジ時間 62,680 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
73,064 KB
testcase_01 AC 110 ms
73,384 KB
testcase_02 WA -
testcase_03 AC 1,612 ms
224,008 KB
testcase_04 AC 2,121 ms
272,896 KB
testcase_05 AC 1,832 ms
235,332 KB
testcase_06 AC 1,898 ms
268,872 KB
testcase_07 AC 1,712 ms
258,756 KB
testcase_08 AC 1,466 ms
222,908 KB
testcase_09 AC 1,863 ms
268,420 KB
testcase_10 WA -
testcase_11 AC 1,921 ms
269,868 KB
testcase_12 AC 1,956 ms
271,680 KB
testcase_13 AC 1,874 ms
248,132 KB
testcase_14 AC 1,635 ms
261,136 KB
testcase_15 AC 1,730 ms
247,752 KB
testcase_16 AC 2,173 ms
272,512 KB
testcase_17 AC 2,065 ms
264,996 KB
testcase_18 AC 1,714 ms
246,532 KB
testcase_19 AC 1,955 ms
268,692 KB
testcase_20 AC 1,899 ms
272,484 KB
testcase_21 AC 1,964 ms
265,444 KB
testcase_22 AC 1,850 ms
271,280 KB
testcase_23 AC 1,969 ms
257,652 KB
testcase_24 AC 1,926 ms
266,864 KB
testcase_25 AC 2,094 ms
268,544 KB
testcase_26 AC 1,821 ms
261,904 KB
testcase_27 AC 1,972 ms
268,276 KB
testcase_28 AC 1,640 ms
235,708 KB
testcase_29 WA -
testcase_30 AC 2,025 ms
272,036 KB
testcase_31 AC 2,188 ms
271,780 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 1,697 ms
270,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import deepcopy
from collections import deque
n,m = map(int,input().split())
e = [[] for i in range(n)]
for i in range(m):
    u,v,c,d = map(int,input().split())
    u -= 1
    v -= 1
    e[u].append([v,c,d])
    e[v].append([u,c,d])
def search(a,b,g):

    dis = [10**20]*n
    dis[a] = 0
    par = [-1]*n
    q = deque([a])
    while q:
        now = q.popleft()
        for nex,c,d in g[now]:
            if dis[nex] > dis[now]+c:
                dis[nex] = dis[now]+c
                par[nex] = now
                q.append(nex)
    ans = dis[b]
    now = b
    while par[now] != -1:
        p = par[now]
        for i in range(len(g[now])):
            if g[now][i][0] == p:
                g[now][i][1] = -1
                break
        now = p
    dis = [10**20]*n
    dis[b] = 0
    q = deque([b])
    while q:
        now = q.popleft()
        for nex,c,d in g[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[a]
    return ans
print(min(search(0,n-1,deepcopy(e)),search(n-1,0,deepcopy(e))))
0