結果

問題 No.2179 Planet Traveler
ユーザー katonyonkokatonyonko
提出日時 2023-01-06 22:40:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 984 ms / 3,000 ms
コード長 1,600 bytes
コンパイル時間 703 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 125,560 KB
最終ジャッジ日時 2023-08-20 15:59:09
合計ジャッジ時間 16,191 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
70,760 KB
testcase_01 AC 60 ms
71,220 KB
testcase_02 AC 60 ms
71,084 KB
testcase_03 AC 60 ms
71,184 KB
testcase_04 AC 64 ms
71,188 KB
testcase_05 AC 66 ms
71,180 KB
testcase_06 AC 61 ms
71,236 KB
testcase_07 AC 65 ms
75,304 KB
testcase_08 AC 71 ms
76,100 KB
testcase_09 AC 71 ms
76,028 KB
testcase_10 AC 71 ms
76,100 KB
testcase_11 AC 839 ms
119,172 KB
testcase_12 AC 962 ms
119,992 KB
testcase_13 AC 984 ms
117,396 KB
testcase_14 AC 846 ms
123,876 KB
testcase_15 AC 845 ms
123,932 KB
testcase_16 AC 837 ms
123,900 KB
testcase_17 AC 977 ms
124,160 KB
testcase_18 AC 965 ms
125,560 KB
testcase_19 AC 943 ms
116,048 KB
testcase_20 AC 175 ms
82,984 KB
testcase_21 AC 910 ms
118,416 KB
testcase_22 AC 599 ms
112,944 KB
testcase_23 AC 468 ms
92,772 KB
testcase_24 AC 777 ms
116,308 KB
testcase_25 AC 613 ms
114,060 KB
testcase_26 AC 832 ms
116,368 KB
testcase_27 AC 175 ms
83,052 KB
testcase_28 AC 395 ms
89,588 KB
testcase_29 AC 786 ms
116,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n
  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]
  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x == y:
      return
    if self.parents[x] > self.parents[y]:
      x, y = y, x
    self.parents[x] += self.parents[y]
    self.parents[y] = x
  def size(self, x):
    return -self.parents[self.find(x)]
  def same(self, x, y):
    return self.find(x) == self.find(y)
  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]
  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]
  def group_count(self):
    return len(self.roots())
  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()}
  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N=int(input())
P=[list(map(int,input().split())) for _ in range(N)]
d=[]
for i in range(N):
  Xi,Yi,Ti=P[i]
  x=Xi**2+Yi**2
  for j in range(i+1,N):
    Xj,Yj,Tj=P[j]
    y=Xj**2+Yj**2
    if Ti==Tj: d.append(((Xi-Xj)**2+(Yi-Yj)**2,i,j))
    else:
      l,r=-1,2*(x+y)
      while r-l>1:
        mid=(l+r)//2
        if mid*(mid-2*(x+y))<=4*x*y-x**2-y**2-2*x*y: r=mid
        else: l=mid
      d.append((r,i,j))
d.sort()
uf=UnionFind(N)
for i in range(len(d)):
  dis,s,t=d[i]
  uf.union(s,t)
  if uf.find(0)==uf.find(N-1):
    print(dis)
    break
0