結果

問題 No.2179 Planet Traveler
ユーザー taiga0629kyoprotaiga0629kyopro
提出日時 2022-09-26 18:10:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 876 ms / 3,000 ms
コード長 1,931 bytes
コンパイル時間 456 ms
コンパイル使用メモリ 87,024 KB
実行使用メモリ 141,688 KB
最終ジャッジ日時 2023-08-20 13:59:53
合計ジャッジ時間 14,542 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,652 KB
testcase_01 AC 73 ms
71,400 KB
testcase_02 AC 74 ms
71,736 KB
testcase_03 AC 74 ms
71,352 KB
testcase_04 AC 73 ms
71,668 KB
testcase_05 AC 71 ms
71,860 KB
testcase_06 AC 73 ms
70,900 KB
testcase_07 AC 73 ms
71,528 KB
testcase_08 AC 85 ms
76,196 KB
testcase_09 AC 85 ms
76,468 KB
testcase_10 AC 85 ms
76,136 KB
testcase_11 AC 638 ms
118,888 KB
testcase_12 AC 807 ms
141,436 KB
testcase_13 AC 876 ms
141,688 KB
testcase_14 AC 669 ms
124,600 KB
testcase_15 AC 665 ms
124,592 KB
testcase_16 AC 648 ms
124,344 KB
testcase_17 AC 870 ms
140,128 KB
testcase_18 AC 869 ms
140,472 KB
testcase_19 AC 861 ms
139,712 KB
testcase_20 AC 193 ms
84,108 KB
testcase_21 AC 819 ms
125,944 KB
testcase_22 AC 543 ms
108,908 KB
testcase_23 AC 427 ms
104,104 KB
testcase_24 AC 696 ms
127,624 KB
testcase_25 AC 535 ms
111,236 KB
testcase_26 AC 726 ms
127,308 KB
testcase_27 AC 171 ms
84,332 KB
testcase_28 AC 369 ms
98,120 KB
testcase_29 AC 680 ms
128,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #







class unionfind:
    def __init__(self,uni_num):
        self.uni_num=uni_num
        self.union_root = [-1 for i in range(self.uni_num + 1)]
        self.union_depth = [0] * (self.uni_num + 1)
        self.e_num=[0]*(self.uni_num+1)

    def find(self,x):  # 親は誰?
        if self.union_root[x] < 0:
            return x
        else:
            self.union_root[x] = self.find(self.union_root[x])
            return self.union_root[x]

    def unite(self,x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            self.e_num[x]+=1
            return
        if self.union_depth[x] < self.union_depth[y]:
            x, y = y, x
        if self.union_depth[x] == self.union_depth[y]:
            self.union_depth[x] += 1
        self.union_root[x] += self.union_root[y]
        self.union_root[y] = x
        self.e_num[x]+=self.e_num[y]+1


    def size(self,x):
        return -self.union_root[self.find(x)]

    def same(self,x,y):
        return self.find(x)==self.find(y)
    def edge(self,x):
        return self.e_num[self.find(x)]





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
        def f(s):
            if s<0:return 0
            if ri2+rj2-s<0:return 1
            return (ri2+rj2-s)**2<=4*ri2*rj2
        ng=int(abs(ri2**0.5-rj2**0.5)**2)-10
        ok=ng+20
        while ok-ng>1:
            mid=(ok+ng)//2
            if f(mid):ok=mid
            else:ng=mid
        return ok

e=[]
for i in range(1,n+1):
    for j in range(i+1,n+1):
        c=cost(i,j)
        e.append((i,j,c))
e.sort(key=lambda x:x[2])
uf=unionfind(n+4)
for i,j,c in e:
    uf.unite(i,j)
    if uf.same(1,n):
        print(c)
        exit()


0