結果

問題 No.807 umg tours
ユーザー ttrttr
提出日時 2020-06-21 20:35:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 843 bytes
コンパイル時間 407 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 160,084 KB
最終ジャッジ日時 2023-09-16 18:53:21
合計ジャッジ時間 28,812 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
75,936 KB
testcase_01 WA -
testcase_02 AC 145 ms
78,032 KB
testcase_03 AC 135 ms
77,888 KB
testcase_04 WA -
testcase_05 AC 108 ms
76,944 KB
testcase_06 AC 149 ms
78,128 KB
testcase_07 AC 133 ms
77,936 KB
testcase_08 AC 79 ms
71,100 KB
testcase_09 AC 94 ms
75,968 KB
testcase_10 AC 92 ms
75,964 KB
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 947 ms
108,400 KB
testcase_21 AC 1,000 ms
109,724 KB
testcase_22 AC 505 ms
90,040 KB
testcase_23 AC 423 ms
86,592 KB
testcase_24 AC 1,241 ms
142,384 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
    a,b,c = map(int, input().split())
    a -= 1
    b -= 1
    E[a].append(c*N+b)
    E[b].append(c*N+a)

import heapq
inf = 10**15
d1 = [inf]*N
d2 = [inf]*N
used1 = [0]*N
used2 = [0]*N
h1 = [0]
while h1:
    temp = heapq.heappop(h1)
    u = temp%N
    dist = temp//N
    if used1[u]:
        continue
    d1[u] = dist
    used1[u] = 1
    for e in E[u]:
        r = e//N
        v = e%N
        heapq.heappush(h1, (r+dist)*N+v)

h2 = [(0, 0, 0)]
while h2:
    temp = heapq.heappop(h2)
    u = temp[2]
    dist = temp[0]
    len = temp[1]
    if used2[u]:
        continue
    d2[u] = dist
    used2[u] = 1
    for e in E[u]:
        r = e//N
        v = e%N
        heapq.heappush(h2, (dist+min(r, len), max(r, len), v))

for i in range(N):
    print(d1[i]+d2[i])
0