結果

問題 No.807 umg tours
ユーザー Coki628Coki628
提出日時 2020-08-19 12:39:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,290 ms / 4,000 ms
コード長 1,613 bytes
コンパイル時間 1,332 ms
コンパイル使用メモリ 87,468 KB
実行使用メモリ 143,708 KB
最終ジャッジ日時 2023-08-15 12:57:47
合計ジャッジ時間 23,798 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
76,236 KB
testcase_01 AC 92 ms
76,328 KB
testcase_02 AC 94 ms
75,944 KB
testcase_03 AC 91 ms
76,496 KB
testcase_04 AC 86 ms
76,260 KB
testcase_05 AC 87 ms
76,372 KB
testcase_06 AC 90 ms
76,240 KB
testcase_07 AC 90 ms
76,080 KB
testcase_08 AC 79 ms
71,644 KB
testcase_09 AC 79 ms
71,660 KB
testcase_10 AC 78 ms
71,888 KB
testcase_11 AC 1,065 ms
113,256 KB
testcase_12 AC 1,318 ms
114,832 KB
testcase_13 AC 1,672 ms
126,248 KB
testcase_14 AC 796 ms
100,996 KB
testcase_15 AC 601 ms
95,724 KB
testcase_16 AC 1,501 ms
125,884 KB
testcase_17 AC 2,277 ms
140,452 KB
testcase_18 AC 2,162 ms
140,560 KB
testcase_19 AC 1,890 ms
135,100 KB
testcase_20 AC 946 ms
112,176 KB
testcase_21 AC 998 ms
112,324 KB
testcase_22 AC 461 ms
92,212 KB
testcase_23 AC 392 ms
88,584 KB
testcase_24 AC 1,100 ms
138,364 KB
testcase_25 AC 2,290 ms
143,708 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