結果

問題 No.807 umg tours
ユーザー Coki628Coki628
提出日時 2020-08-19 12:39:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,498 ms / 4,000 ms
コード長 1,613 bytes
コンパイル時間 948 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 143,348 KB
最終ジャッジ日時 2024-05-03 00:28:13
合計ジャッジ時間 24,310 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
61,568 KB
testcase_01 AC 49 ms
62,592 KB
testcase_02 AC 54 ms
63,488 KB
testcase_03 AC 55 ms
63,616 KB
testcase_04 AC 47 ms
60,672 KB
testcase_05 AC 47 ms
61,056 KB
testcase_06 AC 51 ms
62,592 KB
testcase_07 AC 50 ms
62,208 KB
testcase_08 AC 39 ms
53,120 KB
testcase_09 AC 41 ms
53,888 KB
testcase_10 AC 47 ms
53,248 KB
testcase_11 AC 1,114 ms
111,428 KB
testcase_12 AC 1,395 ms
113,536 KB
testcase_13 AC 1,768 ms
123,264 KB
testcase_14 AC 821 ms
99,072 KB
testcase_15 AC 617 ms
93,824 KB
testcase_16 AC 1,594 ms
124,468 KB
testcase_17 AC 2,411 ms
137,600 KB
testcase_18 AC 2,299 ms
137,600 KB
testcase_19 AC 2,008 ms
133,760 KB
testcase_20 AC 996 ms
109,824 KB
testcase_21 AC 1,010 ms
111,232 KB
testcase_22 AC 472 ms
90,476 KB
testcase_23 AC 366 ms
87,040 KB
testcase_24 AC 1,199 ms
136,092 KB
testcase_25 AC 2,498 ms
143,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

def dijkstra(nodes: list, src: int) -> list:
    """ ダイクストラ(隣接リスト(0-indexed), 始点) """
    from heapq import heappush, heappop

    N = len(nodes)
    res = list2d(2, N, INF)
    que = [(0, 0, src)]
    res[0][src] = 0
    while que:
        dist, flag, cur = heappop(que)
        if res[flag][cur] < dist:
            continue
        for nxt, cost in nodes[cur]:
            if dist + cost < res[flag][nxt]:
                res[flag][nxt] = dist + cost
                heappush(que, (dist+cost, flag, nxt))
            if not flag and dist < res[1][nxt]:
                res[1][nxt] = dist
                heappush(que, (dist, 1, nxt))
    return res

N, M = MAP()
nodes = [[] for i in range(N)]
for _ in range(M):
    a, b, c = MAP()
    a -= 1; b -= 1
    nodes[a].append((b, c))
    nodes[b].append((a, c))

res = dijkstra(nodes, 0)
for i in range(N):
    ans = min(res[0][i]*2, res[0][i]+res[1][i])
    print(ans)
0