結果

問題 No.2179 Planet Traveler
ユーザー lam6er
提出日時 2025-04-16 16:19:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,398 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 82,532 KB
実行使用メモリ 124,164 KB
最終ジャッジ日時 2025-04-16 16:21:10
合計ジャッジ時間 4,318 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 25 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
import heapq

def main():
    n = int(input())
    planets = []
    for _ in range(n):
        x, y, t = map(int, input().split())
        r = math.hypot(x, y)
        planets.append((x, y, t, r))
    
    # Build adjacency list
    adj = [[] for _ in range(n)]
    for i in range(n):
        x_i, y_i, t_i, r_i = planets[i]
        for j in range(n):
            if i == j:
                continue
            x_j, y_j, t_j, r_j = planets[j]
            if t_i == t_j:
                dx = x_i - x_j
                dy = y_i - y_j
                d_sq = dx * dx + dy * dy
            else:
                d_sq = (r_i - r_j) ** 2
            adj[i].append((j, d_sq))
    
    # Dijkstra's algorithm to find minimal maximum edge weight
    dist = [math.inf] * n
    dist[0] = 0.0  # Starting at planet 1 (index 0)
    heap = []
    heapq.heappush(heap, (0.0, 0))
    
    while heap:
        current_max, u = heapq.heappop(heap)
        if u == n - 1:
            print(math.ceil(current_max))
            return
        if current_max > dist[u]:
            continue
        for v, weight in adj[u]:
            new_max = max(current_max, weight)
            if new_max < dist[v]:
                dist[v] = new_max
                heapq.heappush(heap, (new_max, v))
    
    # If no path found (though problem states it's possible)
    print(-1)

if __name__ == "__main__":
    main()
0