結果

問題 No.2179 Planet Traveler
ユーザー taiga0629kyoprotaiga0629kyopro
提出日時 2022-09-26 19:14:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,394 bytes
コンパイル時間 439 ms
コンパイル使用メモリ 87,304 KB
実行使用メモリ 108,776 KB
最終ジャッジ日時 2023-08-20 14:00:14
合計ジャッジ時間 8,514 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
71,932 KB
testcase_01 AC 83 ms
71,424 KB
testcase_02 AC 91 ms
71,800 KB
testcase_03 AC 87 ms
71,480 KB
testcase_04 AC 88 ms
71,744 KB
testcase_05 AC 88 ms
71,716 KB
testcase_06 AC 88 ms
71,096 KB
testcase_07 AC 86 ms
71,708 KB
testcase_08 AC 91 ms
75,800 KB
testcase_09 AC 94 ms
76,416 KB
testcase_10 AC 95 ms
76,272 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 246 ms
102,304 KB
testcase_15 AC 244 ms
101,764 KB
testcase_16 AC 247 ms
102,636 KB
testcase_17 AC 450 ms
108,624 KB
testcase_18 AC 353 ms
104,592 KB
testcase_19 AC 447 ms
108,776 KB
testcase_20 AC 179 ms
82,036 KB
testcase_21 AC 335 ms
100,792 KB
testcase_22 AC 273 ms
94,208 KB
testcase_23 AC 286 ms
93,336 KB
testcase_24 AC 360 ms
100,240 KB
testcase_25 AC 280 ms
94,380 KB
testcase_26 AC 409 ms
102,948 KB
testcase_27 AC 175 ms
82,040 KB
testcase_28 AC 251 ms
89,868 KB
testcase_29 AC 410 ms
103,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #



#WA#

########################################
from heapq import heappush, heappop
def dijkstra( G, s, INF=10 ** 18):
    """
    https://tjkendev.github.io/procon-library/python/graph/dijkstra.html
    O((|E|+|V|)log|V|)
    V: 頂点数
    G[v] = [(nod, cost)]:
        頂点vから遷移可能な頂点(nod)とそのコスト(cost)
    s: 始点の頂点"""

    N=len(G)
    N+=1
    dist = [INF] * N
    hp = [(0, s)]  # (c, v)
    dist[s] = 0
    while hp:
        c, v = heappop(hp)  #vまで行くコストがc
        if dist[v] < c:
            continue
        for u, cost in G[v]:
            if max(dist[v] , cost) < dist[u]:
                dist[u] = max(dist[v] , cost)
                heappush(hp, (dist[u], u))
    return dist
##################################################



n=int(input())
x=[0]
y=[0]
t=[0]
for i in range(n):
    a,b,c=map(int,input().split())
    x.append(a)
    y.append(b)
    t.append(c)
def cost(i,j):
    if t[i]==t[j]:
        return (x[i]-x[j])**2+(y[i]-y[j])**2
    else:
        ri2 = x[i] ** 2 + y[i] ** 2
        rj2 = x[j] ** 2 + y[j] ** 2
        m=ri2+rj2-2*(ri2**0.5)*(rj2**0.5)
        if m==int(m):return int(m)
        return int(m)+1

root=[[] for i in range(n+5)]
for i in range(1,n+1):
    for j in range(i+1,n+1):
        c=cost(i,j)
        root[i].append((j,c))
        root[j].append((i,c))

print(dijkstra(root,1)[n])



0