結果

問題 No.807 umg tours
ユーザー chineristACchineristAC
提出日時 2020-10-25 23:27:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,286 ms / 4,000 ms
コード長 1,430 bytes
コンパイル時間 899 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 254,760 KB
最終ジャッジ日時 2023-09-29 02:22:24
合計ジャッジ時間 27,133 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
76,248 KB
testcase_01 AC 92 ms
76,284 KB
testcase_02 AC 95 ms
76,100 KB
testcase_03 AC 93 ms
76,400 KB
testcase_04 AC 89 ms
76,140 KB
testcase_05 AC 88 ms
76,404 KB
testcase_06 AC 93 ms
76,172 KB
testcase_07 AC 96 ms
76,164 KB
testcase_08 AC 76 ms
71,448 KB
testcase_09 AC 77 ms
71,348 KB
testcase_10 AC 80 ms
75,568 KB
testcase_11 AC 1,451 ms
209,916 KB
testcase_12 AC 1,346 ms
174,820 KB
testcase_13 AC 1,822 ms
217,460 KB
testcase_14 AC 971 ms
138,712 KB
testcase_15 AC 760 ms
126,308 KB
testcase_16 AC 1,854 ms
227,060 KB
testcase_17 AC 2,286 ms
250,496 KB
testcase_18 AC 2,226 ms
250,060 KB
testcase_19 AC 2,250 ms
245,900 KB
testcase_20 AC 1,059 ms
160,268 KB
testcase_21 AC 1,137 ms
164,600 KB
testcase_22 AC 565 ms
115,144 KB
testcase_23 AC 490 ms
108,048 KB
testcase_24 AC 989 ms
222,804 KB
testcase_25 AC 2,209 ms
254,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Dijkstra():
    class Edge():
        def __init__(self, _to, _cost):
            self.to = _to
            self.cost = _cost

    def __init__(self, V):
        self.G = [[] for i in range(V)]
        self._E = 0
        self._V = V

    @property
    def E(self):
        return self._E

    @property
    def V(self):
        return self._V

    def add(self, _from, _to, _cost):
        self.G[_from].append(self.Edge(_to, _cost))
        self._E += 1

    def shortest_path(self, s):
        import heapq
        que = []
        d = [10**15] * self.V
        d[s] = 0
        heapq.heappush(que, (0, s))

        while len(que) != 0:
            cost, v = heapq.heappop(que)
            if d[v] < cost: continue

            for i in range(len(self.G[v])):
                e = self.G[v][i]
                if d[e.to] > d[v] + e.cost:
                    d[e.to] = d[v] + e.cost
                    heapq.heappush(que, (d[e.to], e.to))
        return d

import sys

input = sys.stdin.readline

N,M = map(int,input().split())
tour = Dijkstra(2*N)
for i in range(M):
    a,b,c = map(int,input().split())
    tour.add(2*a-2,2*b-2,c)
    tour.add(2*a-1,2*b-1,c)
    tour.add(2*a-1,2*b-2,0)
    a,b = b,a
    tour.add(2*a-2,2*b-2,c)
    tour.add(2*a-1,2*b-1,c)
    tour.add(2*a-1,2*b-2,0)

short_go = tour.shortest_path(1)
short_back = tour.shortest_path(0)
for i in range(N):
    print(short_go[2*i]*(i>0)+short_back[2*i])
0