結果

問題 No.807 umg tours
ユーザー tempura_pptempura_pp
提出日時 2019-03-17 01:54:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,798 ms / 4,000 ms
コード長 866 bytes
コンパイル時間 647 ms
コンパイル使用メモリ 87,008 KB
実行使用メモリ 154,568 KB
最終ジャッジ日時 2023-08-15 11:49:03
合計ジャッジ時間 27,144 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
75,900 KB
testcase_01 AC 90 ms
75,680 KB
testcase_02 AC 100 ms
75,756 KB
testcase_03 AC 94 ms
75,920 KB
testcase_04 AC 90 ms
75,748 KB
testcase_05 AC 90 ms
76,276 KB
testcase_06 AC 98 ms
76,308 KB
testcase_07 AC 93 ms
75,912 KB
testcase_08 AC 79 ms
71,412 KB
testcase_09 AC 80 ms
71,440 KB
testcase_10 AC 82 ms
71,388 KB
testcase_11 AC 1,300 ms
114,408 KB
testcase_12 AC 1,619 ms
122,348 KB
testcase_13 AC 1,890 ms
130,672 KB
testcase_14 AC 945 ms
103,348 KB
testcase_15 AC 672 ms
97,604 KB
testcase_16 AC 1,878 ms
131,748 KB
testcase_17 AC 2,601 ms
150,164 KB
testcase_18 AC 2,608 ms
149,640 KB
testcase_19 AC 2,221 ms
145,052 KB
testcase_20 AC 1,187 ms
124,076 KB
testcase_21 AC 1,269 ms
126,984 KB
testcase_22 AC 605 ms
98,440 KB
testcase_23 AC 513 ms
93,212 KB
testcase_24 AC 1,212 ms
147,660 KB
testcase_25 AC 2,798 ms
154,568 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