結果

問題 No.807 umg tours
ユーザー tempura_pptempura_pp
提出日時 2019-03-17 01:36:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 3,010 ms / 4,000 ms
コード長 816 bytes
コンパイル時間 389 ms
コンパイル使用メモリ 10,880 KB
実行使用メモリ 182,768 KB
最終ジャッジ日時 2023-09-18 09:33:00
合計ジャッジ時間 28,634 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,480 KB
testcase_01 AC 19 ms
8,328 KB
testcase_02 AC 20 ms
8,560 KB
testcase_03 AC 19 ms
8,592 KB
testcase_04 AC 18 ms
8,336 KB
testcase_05 AC 19 ms
8,344 KB
testcase_06 AC 21 ms
8,516 KB
testcase_07 AC 20 ms
8,412 KB
testcase_08 AC 16 ms
8,152 KB
testcase_09 AC 17 ms
8,284 KB
testcase_10 AC 17 ms
8,312 KB
testcase_11 AC 1,857 ms
134,172 KB
testcase_12 AC 1,683 ms
104,752 KB
testcase_13 AC 2,317 ms
144,064 KB
testcase_14 AC 928 ms
68,192 KB
testcase_15 AC 666 ms
55,348 KB
testcase_16 AC 2,354 ms
151,428 KB
testcase_17 AC 3,010 ms
176,072 KB
testcase_18 AC 2,881 ms
174,076 KB
testcase_19 AC 2,709 ms
170,268 KB
testcase_20 AC 1,241 ms
95,836 KB
testcase_21 AC 1,265 ms
99,128 KB
testcase_22 AC 513 ms
47,596 KB
testcase_23 AC 393 ms
39,280 KB
testcase_24 AC 1,411 ms
135,808 KB
testcase_25 AC 3,009 ms
182,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush
def solve() : 
    N, M = map(int, input().split())

    edge = [[] for i in range(2*N)]
    for i in range(M):
        a, b, c = map(int, input().split())
        a-=1
        b-=1
        edge[a].append((c, b))
        edge[b].append((c, a))
        edge[a+N].append((c, b+N))
        edge[b+N].append((c, a+N))
        edge[a].append((0, b+N))
        edge[b].append((0, a+N))

    dist=[float('inf')]*(2*N)
    dist[0]=dist[N]=0

    pq = []
    heappush(pq, (0,0))
    heappush(pq, (0,N))
    while pq:
        d, cur = heappop(pq)
        if d > dist[cur]: continue

        for cost, to in edge[cur]:
            if dist[to]>d+cost : 
                dist[to]=d+cost
                heappush(pq, (d+cost,to))
    for i in range(N) :
        print(dist[i]+dist[i+N])
solve()
0