結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-02 01:29:28 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,674 ms / 4,000 ms |
| コード長 | 811 bytes |
| コンパイル時間 | 207 ms |
| コンパイル使用メモリ | 82,552 KB |
| 実行使用メモリ | 203,432 KB |
| 最終ジャッジ日時 | 2024-10-02 01:29:50 |
| 合計ジャッジ時間 | 18,273 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
from heapq import heappop, heappush
N, M = map(int, input().split())
graph = [[] for _ in range(N)]
C = dict()
for _ in range(M):
a, b, c = map(int, input().split())
a -= 1; b -= 1
graph[a].append((b, c))
graph[b].append((a, c))
C[a, b] = C[b, a] = c
INF = 10**18
D = [INF] * 2*N
hq = [(0, 0), (0, N)]
while hq:
d, node = heappop(hq)
if D[node] != INF:
continue
D[node] = d
if node >= N:
n = node - N
for nex, c in graph[n]:
if D[nex+N] == INF:
heappush(hq, (d+c, nex+N))
else:
for nex, c in graph[node]:
if D[nex] == INF:
heappush(hq, (d+c, nex))
if D[nex+N] == INF:
heappush(hq, (d, nex+N))
ans = [D[i]+D[i+N] for i in range(N)]
print(*ans, sep='\n')