結果

問題 No.807 umg tours
ユーザー momotaros300momotaros300
提出日時 2019-10-26 17:53:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,783 ms / 4,000 ms
コード長 1,294 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 158,168 KB
最終ジャッジ日時 2024-05-03 00:03:41
合計ジャッジ時間 26,973 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
60,928 KB
testcase_01 AC 51 ms
61,440 KB
testcase_02 AC 55 ms
62,720 KB
testcase_03 AC 60 ms
62,592 KB
testcase_04 AC 53 ms
60,544 KB
testcase_05 AC 58 ms
60,544 KB
testcase_06 AC 59 ms
62,336 KB
testcase_07 AC 59 ms
62,720 KB
testcase_08 AC 43 ms
52,992 KB
testcase_09 AC 44 ms
53,632 KB
testcase_10 AC 46 ms
53,248 KB
testcase_11 AC 1,308 ms
114,560 KB
testcase_12 AC 1,558 ms
123,264 KB
testcase_13 AC 2,016 ms
131,968 KB
testcase_14 AC 967 ms
103,972 KB
testcase_15 AC 623 ms
96,896 KB
testcase_16 AC 1,782 ms
134,144 KB
testcase_17 AC 2,739 ms
152,480 KB
testcase_18 AC 2,658 ms
151,296 KB
testcase_19 AC 2,365 ms
145,536 KB
testcase_20 AC 1,220 ms
124,544 KB
testcase_21 AC 1,357 ms
127,360 KB
testcase_22 AC 597 ms
97,652 KB
testcase_23 AC 511 ms
93,816 KB
testcase_24 AC 1,146 ms
150,400 KB
testcase_25 AC 2,783 ms
158,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf=float('inf')
import heapq

def disktra(g,s):
    n=len(g)
    dist = [[inf]*2 for i in range(n)]
    maxd=[0]*n
    dist[s][0] = 0
    dist[s][1]=0
    hq=[]
    heapq.heappush(hq,(dist[s][0],s,0))
    while hq:
        cost,u,used =heapq.heappop(hq)
        if dist[u][used] < cost:
            continue
        if used ==0:
            for v, c in g[u]:
                # print(dist[v][1])
                # print(v)
                if dist[v][1] <= dist[u][0] :pass
                else:
                    dist[v][1] = dist[u][0]
                    heapq.heappush(hq, (dist[v][1], v, 1))

            
        for v,c in g[u]:
            if dist[v][used] <= dist[u][used] +c:
                continue
            dist[v][used] = dist[u][used] + c
            
            heapq.heappush(hq,(dist[v][used],v,used))
    return dist

n,m=map(int,input().split())
abc=[]
G=[[]*n for i in range(n)]
G2=[[]*n for i in range(n)]

for i in range(m):
    a,b,c=map(int,input().split())
    a-=1;b-=1
    G[a].append((b,c))
    G[b].append((a,c))
d1=disktra(G,0)
# d2=disktra(G,0)
for i in range(n):
    ans=min(d1[i][1]+d1[i][0],d1[i][0]+d1[i][1])
    print(ans)
# print(d1)
# print(d2)
0