結果

問題 No.807 umg tours
ユーザー lllllll88938494lllllll88938494
提出日時 2023-05-10 17:03:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,550 ms / 4,000 ms
コード長 948 bytes
コンパイル時間 512 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 162,896 KB
最終ジャッジ日時 2024-11-26 22:04:40
合計ジャッジ時間 26,037 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
61,568 KB
testcase_01 AC 54 ms
62,080 KB
testcase_02 AC 60 ms
64,768 KB
testcase_03 AC 60 ms
63,872 KB
testcase_04 AC 51 ms
60,928 KB
testcase_05 AC 51 ms
60,672 KB
testcase_06 AC 63 ms
64,768 KB
testcase_07 AC 57 ms
63,360 KB
testcase_08 AC 40 ms
52,352 KB
testcase_09 AC 41 ms
52,864 KB
testcase_10 AC 41 ms
53,504 KB
testcase_11 AC 1,082 ms
115,708 KB
testcase_12 AC 1,392 ms
126,416 KB
testcase_13 AC 1,712 ms
136,004 KB
testcase_14 AC 795 ms
105,264 KB
testcase_15 AC 561 ms
97,808 KB
testcase_16 AC 1,682 ms
136,696 KB
testcase_17 AC 2,400 ms
157,148 KB
testcase_18 AC 2,349 ms
155,192 KB
testcase_19 AC 2,139 ms
151,296 KB
testcase_20 AC 1,223 ms
129,988 KB
testcase_21 AC 1,296 ms
133,008 KB
testcase_22 AC 570 ms
99,020 KB
testcase_23 AC 481 ms
94,308 KB
testcase_24 AC 1,164 ms
156,868 KB
testcase_25 AC 2,550 ms
162,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify as hpi , heappop as hpop , heappush as hpush
n,m=map(int,input().split())
g = [[] for i in range(n)]
for _ in range(m):
    x,y,z = map(int,input().split())
    x-=1
    y-=1
    g[x].append((y,z))
    g[y].append((x,z))

inf=float('inf')
d = [[inf,inf] for i in range(n)]
d[0][0] = 0
d[0][1] = 0
done=[[0,0] for i in range(n)]
hp=[]

def  daiku(i,f):
    hpush(hp,(d[i][f],i,f))
    
    while hp:
        _ ,now,ch= hpop(hp)
        if done[now][ch]:
            continue
            
        done[now][ch] = 1
    
        for go,cost in g[now]:
            if d[go][ch] > d[now][ch] + cost:
                d[go][ch] = d[now][ch] + cost
                hpush(hp,(d[go][ch],go,ch))
            if ch == 0:
                if d[go][ch+1] > d[now][ch]:
                    d[go][ch+1] = d[now][ch]
                    hpush(hp,(d[go][ch+1],go,ch+1))
            
daiku(0,0)
for i in range(n):
    print(d[i][0] + d[i][1])
0