結果

問題 No.807 umg tours
ユーザー lllllll88938494lllllll88938494
提出日時 2023-05-10 17:03:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,890 ms / 4,000 ms
コード長 948 bytes
コンパイル時間 411 ms
コンパイル使用メモリ 87,016 KB
実行使用メモリ 164,968 KB
最終ジャッジ日時 2023-08-17 21:30:36
合計ジャッジ時間 29,469 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
75,668 KB
testcase_01 AC 91 ms
75,668 KB
testcase_02 AC 99 ms
75,812 KB
testcase_03 AC 96 ms
75,816 KB
testcase_04 AC 89 ms
75,844 KB
testcase_05 AC 90 ms
75,704 KB
testcase_06 AC 99 ms
76,220 KB
testcase_07 AC 95 ms
75,912 KB
testcase_08 AC 78 ms
71,344 KB
testcase_09 AC 80 ms
71,192 KB
testcase_10 AC 81 ms
71,044 KB
testcase_11 AC 1,331 ms
115,316 KB
testcase_12 AC 1,607 ms
128,724 KB
testcase_13 AC 1,990 ms
139,912 KB
testcase_14 AC 952 ms
106,608 KB
testcase_15 AC 666 ms
99,664 KB
testcase_16 AC 1,962 ms
140,300 KB
testcase_17 AC 2,756 ms
159,456 KB
testcase_18 AC 2,672 ms
158,444 KB
testcase_19 AC 2,422 ms
154,336 KB
testcase_20 AC 1,334 ms
132,688 KB
testcase_21 AC 1,393 ms
135,408 KB
testcase_22 AC 639 ms
101,268 KB
testcase_23 AC 559 ms
96,440 KB
testcase_24 AC 1,245 ms
159,200 KB
testcase_25 AC 2,890 ms
164,968 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