結果

問題 No.807 umg tours
ユーザー terasaterasa
提出日時 2022-06-02 22:01:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,372 ms / 4,000 ms
コード長 1,817 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 81,760 KB
実行使用メモリ 195,904 KB
最終ジャッジ日時 2023-10-21 01:20:17
合計ジャッジ時間 17,163 ms
ジャッジサーバーID
(参考情報)
judge13 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
63,700 KB
testcase_01 AC 53 ms
66,064 KB
testcase_02 AC 59 ms
68,396 KB
testcase_03 AC 53 ms
65,748 KB
testcase_04 AC 54 ms
66,292 KB
testcase_05 AC 52 ms
63,828 KB
testcase_06 AC 54 ms
65,748 KB
testcase_07 AC 52 ms
63,700 KB
testcase_08 AC 43 ms
55,816 KB
testcase_09 AC 43 ms
55,816 KB
testcase_10 AC 44 ms
55,816 KB
testcase_11 AC 757 ms
144,732 KB
testcase_12 AC 806 ms
143,936 KB
testcase_13 AC 1,047 ms
163,068 KB
testcase_14 AC 519 ms
115,508 KB
testcase_15 AC 388 ms
106,580 KB
testcase_16 AC 1,039 ms
168,452 KB
testcase_17 AC 1,294 ms
191,752 KB
testcase_18 AC 1,207 ms
191,044 KB
testcase_19 AC 1,136 ms
187,620 KB
testcase_20 AC 617 ms
148,744 KB
testcase_21 AC 678 ms
150,092 KB
testcase_22 AC 340 ms
107,072 KB
testcase_23 AC 280 ms
99,492 KB
testcase_24 AC 635 ms
180,872 KB
testcase_25 AC 1,372 ms
195,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict
import bisect

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')


def index_lt(a, x):
    'return largest index s.t. A[i] < x or -1 if it does not exist'
    return bisect.bisect_left(a, x) - 1


def index_le(a, x):
    'return largest index s.t. A[i] <= x or -1 if it does not exist'
    return bisect.bisect_right(a, x) - 1


def index_gt(a, x):
    'return smallest index s.t. A[i] > x or len(a) if it does not exist'
    return bisect.bisect_right(a, x)


def index_ge(a, x):
    'return smallest index s.t. A[i] >= x or len(a) if it does not exist'
    return bisect.bisect_left(a, x)


class Dijkstra:
    def __init__(self, N, E, inf=1 << 50):
        self.N = N
        self.E = E
        self.inf = inf

    def cost_from(self, s):
        C = [self.inf] * self.N
        C[2 * s] = 0
        C[2 * s + 1] = 0
        h = [(0, s)]
        visited = set()

        while len(h) > 0:
            _, v = heapq.heappop(h)
            if v in visited:
                continue
            visited.add(v)

            for c, d in self.E[v]:
                if C[d] > C[v] + c:
                    C[d] = C[v] + c
                    heapq.heappush(h, (C[d], d))
        return C


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

solver = Dijkstra(2 * N, E)
C = solver.cost_from(0)
for i in range(N):
    print(C[2 * i] + C[2 * i + 1])
0