結果

問題 No.807 umg tours
ユーザー momotaros300momotaros300
提出日時 2019-10-26 17:53:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,650 ms / 4,000 ms
コード長 1,294 bytes
コンパイル時間 74 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 104,704 KB
最終ジャッジ日時 2024-05-03 00:02:30
合計ジャッジ時間 25,085 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,752 KB
testcase_01 AC 28 ms
11,008 KB
testcase_02 AC 29 ms
10,880 KB
testcase_03 AC 31 ms
10,880 KB
testcase_04 AC 29 ms
10,880 KB
testcase_05 AC 30 ms
10,752 KB
testcase_06 AC 30 ms
11,008 KB
testcase_07 AC 28 ms
11,136 KB
testcase_08 AC 26 ms
10,880 KB
testcase_09 AC 28 ms
10,880 KB
testcase_10 AC 27 ms
10,752 KB
testcase_11 AC 1,394 ms
67,200 KB
testcase_12 AC 1,382 ms
64,000 KB
testcase_13 AC 1,893 ms
80,256 KB
testcase_14 AC 750 ms
43,136 KB
testcase_15 AC 566 ms
36,096 KB
testcase_16 AC 1,918 ms
82,556 KB
testcase_17 AC 2,572 ms
99,584 KB
testcase_18 AC 2,591 ms
98,560 KB
testcase_19 AC 2,470 ms
95,744 KB
testcase_20 AC 1,268 ms
65,920 KB
testcase_21 AC 1,318 ms
68,352 KB
testcase_22 AC 508 ms
35,968 KB
testcase_23 AC 372 ms
30,592 KB
testcase_24 AC 1,321 ms
82,868 KB
testcase_25 AC 2,650 ms
104,704 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