結果

問題 No.2179 Planet Traveler
ユーザー rlangevinrlangevin
提出日時 2023-03-19 00:17:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,068 ms / 3,000 ms
コード長 1,590 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 78,100 KB
最終ジャッジ日時 2023-10-18 17:38:05
合計ジャッジ時間 15,406 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,948 KB
testcase_01 AC 38 ms
53,884 KB
testcase_02 AC 37 ms
53,948 KB
testcase_03 AC 40 ms
53,884 KB
testcase_04 AC 37 ms
53,948 KB
testcase_05 AC 37 ms
53,948 KB
testcase_06 AC 37 ms
53,884 KB
testcase_07 AC 54 ms
66,908 KB
testcase_08 AC 91 ms
76,424 KB
testcase_09 AC 96 ms
76,496 KB
testcase_10 AC 83 ms
76,424 KB
testcase_11 AC 426 ms
77,340 KB
testcase_12 AC 1,068 ms
77,600 KB
testcase_13 AC 1,013 ms
77,488 KB
testcase_14 AC 400 ms
77,872 KB
testcase_15 AC 399 ms
77,716 KB
testcase_16 AC 405 ms
77,780 KB
testcase_17 AC 1,036 ms
77,228 KB
testcase_18 AC 1,044 ms
77,488 KB
testcase_19 AC 1,054 ms
77,488 KB
testcase_20 AC 242 ms
77,304 KB
testcase_21 AC 965 ms
77,488 KB
testcase_22 AC 674 ms
77,684 KB
testcase_23 AC 602 ms
77,156 KB
testcase_24 AC 865 ms
77,100 KB
testcase_25 AC 709 ms
77,224 KB
testcase_26 AC 955 ms
77,380 KB
testcase_27 AC 247 ms
77,220 KB
testcase_28 AC 502 ms
77,224 KB
testcase_29 AC 941 ms
78,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]

def dist1(i, j):
    return (X[i] - X[j]) ** 2 + (Y[i] - Y[j]) ** 2

def dist2(i, j):
    return abs(sqrt(X[i] ** 2 + Y[i] ** 2) - sqrt(X[j] ** 2  + Y[j] ** 2))

N = int(input())
X, Y, T = [0] * N, [0] * N, [0] * N
for i in range(N):
    X[i], Y[i], T[i] = map(int, input().split())
    
yes = 10 ** 18 + 5
no = -1
eps = 10**-8
while yes - no != 1:
    mid = (yes + no)//2
    U = UnionFind(N)
    for i in range(N):
        for j in range(i + 1, N):
            if T[i] != T[j]:
                if dist2(i, j) ** 2 - eps <= mid:
                    U.union(i, j)
            else:
                if dist1(i, j) <= mid:
                    U.union(i, j)
    if U.is_same(0, N - 1):
        yes = mid
    else:
        no = mid
        
print(yes)
0