結果

問題 No.807 umg tours
ユーザー 👑 H20H20
提出日時 2021-05-02 14:38:55
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 1,531 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 372,184 KB
最終ジャッジ日時 2023-09-28 05:02:30
合計ジャッジ時間 39,971 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 126 ms
77,412 KB
testcase_07 WA -
testcase_08 AC 93 ms
71,708 KB
testcase_09 AC 99 ms
72,300 KB
testcase_10 AC 102 ms
76,512 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1,530 ms
320,220 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
import heapq


class Dijkstra:
    def __init__(self):
        self.e = collections.defaultdict(list)

    def add(self, u, v, d):
        self.e[u].append([v, d])
        self.e[v].append([u, d])

    def delete(self, u, v):
        self.e[u] = [_ for _ in self.e[u] if _[0] != v]
        self.e[v] = [_ for _ in self.e[v] if _[0] != u]

    def search(self, s):
        """
        :param s: 始点
        :return: 始点から各点までの最短経路
        """
        d = collections.defaultdict(lambda: float('inf'))
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in self.e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

        return d

N, M = map(int, input().split())
ABC = [list(map(int, input().split())) for i in range(M)]
graph1 = Dijkstra()#チケット使用しない
graph2 = Dijkstra()#チケット1枚使用(使用後をマイナスで表現)
for a,b,c in ABC:
    graph1.add(a, b, c)
    graph2.add(a, b, c)
    graph2.add(a, -b, 0)
    graph2.add(-a, -b, c)
g1 = graph1.search(1)
g2 = graph2.search(1)
print(0)#1から1は0、↓の計算でやると別な値が入るため
for i in range(2,N+1):
    print(g1[i]+g2[-i])
0