結果

問題 No.807 umg tours
ユーザー maspymaspy
提出日時 2020-02-27 16:15:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 925 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 10,980 KB
実行使用メモリ 186,956 KB
最終ジャッジ日時 2023-08-15 12:43:13
合計ジャッジ時間 34,802 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,508 KB
testcase_01 AC 19 ms
8,624 KB
testcase_02 AC 22 ms
8,664 KB
testcase_03 AC 21 ms
8,612 KB
testcase_04 AC 18 ms
8,508 KB
testcase_05 AC 19 ms
8,524 KB
testcase_06 AC 21 ms
8,720 KB
testcase_07 AC 21 ms
8,568 KB
testcase_08 AC 17 ms
8,420 KB
testcase_09 AC 17 ms
8,328 KB
testcase_10 AC 17 ms
8,316 KB
testcase_11 AC 2,837 ms
155,584 KB
testcase_12 AC 2,208 ms
108,964 KB
testcase_13 AC 2,648 ms
157,016 KB
testcase_14 AC 1,121 ms
71,096 KB
testcase_15 AC 767 ms
59,552 KB
testcase_16 AC 2,733 ms
169,188 KB
testcase_17 AC 3,420 ms
186,956 KB
testcase_18 AC 3,399 ms
186,904 KB
testcase_19 AC 3,169 ms
186,532 KB
testcase_20 AC 1,355 ms
103,060 KB
testcase_21 AC 1,401 ms
107,256 KB
testcase_22 AC 558 ms
50,756 KB
testcase_23 AC 443 ms
41,772 KB
testcase_24 TLE -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heappop, heappush

# %%
N, M = map(int, readline().split())
m = map(int, read().split())
ABC = zip(m, m, m)


# %%
G = [[] for _ in range(N + N + 1)]
for a, b, c in ABC:
    G[a].append((b, c))
    G[a].append((b + N, 0))
    G[a + N].append((b + N, c))
    G[b].append((a, c))
    G[b].append((a + N, 0))
    G[b + N].append((a + N, c))


# %%
INF = 10**18
dist = [INF] * (N + N + 1)
q = [1]
dist[1] = 0
while q:
    x = heappop(q)
    dv, v = divmod(x, 1 << 20)
    if dist[v] > dv:
        continue
    for w, c in G[v]:
        dw = dv + c
        if dw >= dist[w]:
            continue
        dist[w] = dw
        heappush(q, (dw << 20) + w)


# %%
dist[1 + N] = 0
answer = (x + y for x, y in zip(dist[1:], dist[1 + N:]))
print('\n'.join(map(str, answer)))
0