結果

問題 No.807 umg tours
ユーザー kamojirokamojiro
提出日時 2019-03-22 23:14:23
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 812 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 81,680 KB
実行使用メモリ 169,696 KB
最終ジャッジ日時 2023-10-19 10:25:41
合計ジャッジ時間 12,529 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 43 ms
55,436 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 565 ms
122,000 KB
testcase_21 AC 565 ms
120,348 KB
testcase_22 AC 313 ms
97,904 KB
testcase_23 AC 258 ms
93,240 KB
testcase_24 AC 514 ms
147,644 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**16, 10**16,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