結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-04-14 00:54:08 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 850 bytes |
| コンパイル時間 | 169 ms |
| コンパイル使用メモリ | 82,368 KB |
| 実行使用メモリ | 146,736 KB |
| 最終ジャッジ日時 | 2024-12-24 02:51:47 |
| 合計ジャッジ時間 | 30,617 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 TLE * 1 |
ソースコード
import heapq
N,M = map(int,input().split())
lsg = [[] for i in range(N)]
for i in range(M):
a,b,c = map(int,input().split())
a -= 1
b -= 1
lsg[a].append((b,c))
lsg[b].append((a,c))
h = [(0,0,0)]
INF = float('INF')
cost0 = [INF]*(N)
cost1 = [INF]*(N)
cost0[0] = 0
cost1[0] = 0
while h:
c,n,f = heapq.heappop(h)
for nex,cos in lsg[n]:
if f == 0: # 使える
if cost0[nex] > c + cos: # 使わない
cost0[nex] = c + cos
heapq.heappush(h, (c+cos,nex,0))
if cost1[nex] > c: # 使う
cost1[nex] = c
heapq.heappush(h, (c,nex,1))
if f == 1: # 使えない
if cost1[nex] > c+ cos:
cost1[nex] = c+ cos
heapq.heappush(h, (c+ cos,nex,1))
for i in range(N):
print(cost0[i]+cost1[i])