結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-12-01 01:15:32 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 3,747 ms / 4,000 ms |
| コード長 | 1,202 bytes |
| コンパイル時間 | 316 ms |
| コンパイル使用メモリ | 82,272 KB |
| 実行使用メモリ | 184,296 KB |
| 最終ジャッジ日時 | 2025-01-29 12:46:21 |
| 合計ジャッジ時間 | 34,160 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
# 一回だけコスト0で移動できるダイクストラで、各頂点への距離を「権利使った,使ってない」の二通りで求める
N,M = map(int,input().split())
G = [[] for i in range(N)]
for _ in range(M):
a,b,c = map(int,input().split())
G[a - 1].append([b - 1, c])
G[b - 1].append([a - 1, c])
INF = 1 << 60
dist = [[INF] * 2 for i in range(N)]
import heapq as hq
q = []
hq.heappush(q, (0, 0, False))
dist[0][True] = 0
while q:
d,v,used = hq.heappop(q)
# print("v",v,"d",d,"used",used)
if dist[v][used] != INF:
continue
dist[v][used] = d
for child, c in G[v]:
# print(child,c,"used",used)
# 権利を使える場合
if not used:
if dist[child][True] == INF:
# print("権利を使って",v,"から",child,"に移動")
hq.heappush(q, (d, child, True))
# 権利を使わない場合
if dist[child][used] == INF:
# print("権利を遣わず",v,"から",child,"に移動",used)
hq.heappush(q, (d + c, child, used))
#print(dist)
for i in range(N):
print(dist[i][False] + dist[i][True])