結果

問題 No.807 umg tours
ユーザー kamojirokamojiro
提出日時 2019-03-22 23:07:12
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 813 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 81,608 KB
実行使用メモリ 169,620 KB
最終ジャッジ日時 2023-10-19 10:21:48
合計ジャッジ時間 12,624 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 45 ms
55,372 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 566 ms
121,980 KB
testcase_21 AC 564 ms
120,328 KB
testcase_22 AC 305 ms
97,868 KB
testcase_23 AC 256 ms
93,220 KB
testcase_24 AC 538 ms
147,616 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from collections import deque
N, M = map( int, input().split())
E = [ [] for _ in range(N)]
D = defaultdict( int)
for _ in range(M):
    a, b, c = map( int, input().split())
    a, b = a-1, b-1
    D[(a,b)] = D[(b,a)] = c
    E[a].append(b)
    E[b].append(a)
V = [ [10**15, 10**15,0] for _ in range(N)]
V[0] = [0,0,0]
H = deque(E[0])
P = [0]*N
P[0] = 1

for t in E[0]:
    d = D[(0,t)]
    V[t] = [d,d,d]
    P[t] = 1
while H:
    h = H.popleft()
    q, p, m = V[h]
    for t in E[h]:
        d = D[(h,t)]
        V[t][0] = min(V[t][0], q + d)
        if V[t][1] - V[t][2] >= p + d - max(d,m):
            V[t][1] = p+d
            V[t][2] = max(d,m)
        if P[t] == 0:
            H.append(t)
            P[t] = 1
for i in range(N):
    print(V[i][0] + V[i][1] - V[i][2])
0