結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
63,652 KB
testcase_01 AC 53 ms
66,016 KB
testcase_02 AC 60 ms
68,348 KB
testcase_03 AC 53 ms
65,700 KB
testcase_04 AC 57 ms
66,244 KB
testcase_05 AC 50 ms
63,780 KB
testcase_06 AC 55 ms
65,700 KB
testcase_07 AC 54 ms
63,652 KB
testcase_08 AC 44 ms
55,800 KB
testcase_09 AC 44 ms
55,800 KB
testcase_10 AC 44 ms
55,800 KB
testcase_11 AC 828 ms
144,712 KB
testcase_12 AC 846 ms
143,960 KB
testcase_13 AC 1,095 ms
163,048 KB
testcase_14 AC 547 ms
115,476 KB
testcase_15 AC 412 ms
106,544 KB
testcase_16 AC 1,131 ms
168,436 KB
testcase_17 AC 1,453 ms
191,348 KB
testcase_18 AC 1,407 ms
191,044 KB
testcase_19 AC 1,284 ms
187,608 KB
testcase_20 AC 703 ms
148,600 KB
testcase_21 AC 721 ms
150,084 KB
testcase_22 AC 358 ms
107,060 KB
testcase_23 AC 300 ms
99,480 KB
testcase_24 AC 703 ms
180,860 KB
testcase_25 AC 1,405 ms
195,912 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, 2 * 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