結果

問題 No.807 umg tours
ユーザー FromBooskaFromBooska
提出日時 2023-02-17 16:51:08
言語 PyPy3
(7.3.13)
結果
TLE  
実行時間 -
コード長 1,014 bytes
コンパイル時間 533 ms
コンパイル使用メモリ 86,788 KB
実行使用メモリ 108,600 KB
最終ジャッジ日時 2023-09-26 15:22:28
合計ジャッジ時間 11,493 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
N, M = map(int, stdin.readline().split())
edges = [[] for i in range(N+1)]
for i in range(M):
    a, b, c = map(int, stdin.readline().split())
    edges[a].append((b, c))
    edges[b].append((a, c))

import sys
sys.setrecursionlimit(10**7)

def dfs(current, distance, mx):
    for nxt, nxt_d in edges[current]:
        if visited[nxt] == 0:
            visited[nxt] = 1
            mx_temp = max(mx, nxt_d)
            distance_list[nxt].add((distance+nxt_d, mx_temp, distance+nxt_d - mx_temp))
            dfs(nxt, distance+nxt_d, mx_temp)
            visited[nxt] = 0

distance_list = [set() for i in range(N+1)]
visited = [0]*(N+1)
visited[1] = 1
dfs(1, 0, 0)

for i in range(1, N+1):
    if i == 1:
        print(0)
    else:
        shortest = 10**10
        skip_shortest = 10**10
        for total, dummy, net in distance_list[i]:
            shortest = min(shortest, total)
            skip_shortest = min(skip_shortest, net)
        ans = shortest + skip_shortest
        print(ans)
0