結果

問題 No.807 umg tours
ユーザー tempura_pptempura_pp
提出日時 2019-03-17 01:53:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,499 ms / 4,000 ms
コード長 866 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 10,820 KB
実行使用メモリ 94,748 KB
最終ジャッジ日時 2023-08-15 11:46:51
合計ジャッジ時間 23,386 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,404 KB
testcase_01 AC 16 ms
8,336 KB
testcase_02 AC 17 ms
8,408 KB
testcase_03 AC 17 ms
8,468 KB
testcase_04 AC 16 ms
8,420 KB
testcase_05 AC 17 ms
8,440 KB
testcase_06 AC 16 ms
8,080 KB
testcase_07 AC 16 ms
8,532 KB
testcase_08 AC 14 ms
8,200 KB
testcase_09 AC 16 ms
8,200 KB
testcase_10 AC 16 ms
8,244 KB
testcase_11 AC 1,306 ms
62,196 KB
testcase_12 AC 1,258 ms
56,948 KB
testcase_13 AC 1,735 ms
72,328 KB
testcase_14 AC 687 ms
37,848 KB
testcase_15 AC 502 ms
31,208 KB
testcase_16 AC 1,803 ms
74,564 KB
testcase_17 AC 2,347 ms
89,984 KB
testcase_18 AC 2,428 ms
88,872 KB
testcase_19 AC 2,380 ms
85,832 KB
testcase_20 AC 1,108 ms
61,960 KB
testcase_21 AC 1,159 ms
64,380 KB
testcase_22 AC 405 ms
32,504 KB
testcase_23 AC 303 ms
27,232 KB
testcase_24 AC 1,144 ms
75,032 KB
testcase_25 AC 2,499 ms
94,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

    edge = [[] for i in range(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))

    dist=[[float('inf'),float('inf')]for i in range(N)]
    dist[0]=[0,0]

    pq = []
    heappush(pq, (0,0,0))
    heappush(pq, (0,1,0))
    while pq:
        d, num, cur = heappop(pq)
        if d > dist[cur][num]: continue
        for cost, to in edge[cur]:
            ret = d+cost
            if dist[to][num]>ret : 
                dist[to][num]=ret
                heappush(pq, (ret,num,to))
            if num == 0 :
                if dist[to][1]>d : 
                    dist[to][1]=d
                    heappush(pq, (d,1,to))
    for x,y in dist :
        print(x+y)
solve()
0