結果

問題 No.807 umg tours
ユーザー sinsincoscossinsincoscos
提出日時 2019-03-17 13:38:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,178 ms / 4,000 ms
コード長 905 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 82,012 KB
実行使用メモリ 151,168 KB
最終ジャッジ日時 2024-05-02 23:14:20
合計ジャッジ時間 20,498 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
60,288 KB
testcase_01 AC 42 ms
61,184 KB
testcase_02 AC 44 ms
62,208 KB
testcase_03 AC 44 ms
62,080 KB
testcase_04 AC 44 ms
60,160 KB
testcase_05 AC 46 ms
60,032 KB
testcase_06 AC 48 ms
62,208 KB
testcase_07 AC 47 ms
61,440 KB
testcase_08 AC 38 ms
52,864 KB
testcase_09 AC 38 ms
52,864 KB
testcase_10 AC 38 ms
52,888 KB
testcase_11 AC 894 ms
112,956 KB
testcase_12 AC 1,223 ms
119,088 KB
testcase_13 AC 1,424 ms
129,404 KB
testcase_14 AC 676 ms
101,584 KB
testcase_15 AC 512 ms
95,936 KB
testcase_16 AC 1,413 ms
129,420 KB
testcase_17 AC 2,178 ms
146,444 KB
testcase_18 AC 2,032 ms
146,136 KB
testcase_19 AC 1,706 ms
141,268 KB
testcase_20 AC 899 ms
119,756 KB
testcase_21 AC 998 ms
122,512 KB
testcase_22 AC 442 ms
96,560 KB
testcase_23 AC 382 ms
91,340 KB
testcase_24 AC 1,005 ms
147,452 KB
testcase_25 AC 2,154 ms
151,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush
import sys
input = sys.stdin.readline

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