結果
| 問題 | No.2179 Planet Traveler | 
| コンテスト | |
| ユーザー |  lam6er | 
| 提出日時 | 2025-04-16 16:19:35 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 238 ms / 3,000 ms | 
| コード長 | 1,430 bytes | 
| コンパイル時間 | 444 ms | 
| コンパイル使用メモリ | 81,164 KB | 
| 実行使用メモリ | 124,100 KB | 
| 最終ジャッジ日時 | 2025-04-16 16:21:18 | 
| 合計ジャッジ時間 | 4,526 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 26 | 
ソースコード
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):
        xi, yi, ti, ri = planets[i]
        for j in range(n):
            if i == j:
                continue
            xj, yj, tj, rj = planets[j]
            if ti != tj:
                d_sq = (ri - rj) ** 2
            else:
                dx = xi - xj
                dy = yi - yj
                d_sq = dx * dx + dy * dy
            adj[i].append((j, d_sq))
    
    # Dijkstra's algorithm to find minimal maximum edge weight
    INF = float('inf')
    max_dist = [INF] * n
    max_dist[0] = 0  # Starting at node 0 (planet 1)
    heap = []
    heapq.heappush(heap, (0.0, 0))
    
    while heap:
        current_max, u = heapq.heappop(heap)
        if u == n - 1:
            break
        if current_max > max_dist[u]:
            continue
        for v, w in adj[u]:
            new_max = max(current_max, w)
            if new_max < max_dist[v]:
                max_dist[v] = new_max
                heapq.heappush(heap, (new_max, v))
    
    s = max_dist[n - 1]
    # Compute the ceiling with epsilon to handle precision issues
    result = math.ceil(s - 1e-9)
    print(result)
if __name__ == "__main__":
    main()
            
            
            
        