結果

問題 No.2179 Planet Traveler
ユーザー MasKoaTSMasKoaTS
提出日時 2022-08-02 21:49:47
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 663 ms / 3,000 ms
コード長 1,474 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 86,776 KB
実行使用メモリ 136,836 KB
最終ジャッジ日時 2023-08-20 13:56:20
合計ジャッジ時間 11,774 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
71,500 KB
testcase_01 AC 65 ms
71,236 KB
testcase_02 AC 66 ms
71,276 KB
testcase_03 AC 63 ms
71,480 KB
testcase_04 AC 69 ms
71,576 KB
testcase_05 AC 66 ms
71,448 KB
testcase_06 AC 67 ms
71,412 KB
testcase_07 AC 67 ms
71,432 KB
testcase_08 AC 75 ms
75,168 KB
testcase_09 AC 73 ms
75,408 KB
testcase_10 AC 70 ms
74,960 KB
testcase_11 AC 558 ms
123,096 KB
testcase_12 AC 632 ms
136,056 KB
testcase_13 AC 641 ms
136,420 KB
testcase_14 AC 571 ms
127,468 KB
testcase_15 AC 562 ms
127,840 KB
testcase_16 AC 575 ms
127,632 KB
testcase_17 AC 656 ms
136,828 KB
testcase_18 AC 663 ms
136,836 KB
testcase_19 AC 650 ms
136,176 KB
testcase_20 AC 141 ms
83,952 KB
testcase_21 AC 633 ms
125,868 KB
testcase_22 AC 413 ms
105,676 KB
testcase_23 AC 338 ms
101,216 KB
testcase_24 AC 555 ms
124,172 KB
testcase_25 AC 403 ms
106,528 KB
testcase_26 AC 539 ms
120,044 KB
testcase_27 AC 134 ms
84,384 KB
testcase_28 AC 285 ms
98,292 KB
testcase_29 AC 545 ms
124,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, math
input = sys.stdin.readline

class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1] * n

	def find(self, x):
		if(self.parents[x] < 0):
			return x
		self.parents[x] = self.find(self.parents[x])
		return self.parents[x]

	def unite(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 same(self, x, y):
		return self.find(x) == self.find(y)

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

	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 isqrt(n):
	rn = math.sqrt(n)
	ok = int(rn - 2)
	ng = int(rn + 2)
	while(ng - ok > 1):
		k = (ok + ng) >> 1
		if(k * k <= n):
			ok = k
		else:
			ng = k
	return ok


"""
Main Code
"""

n = int(input())
planet = [list(map(int, input().split())) for _ in [0] * n]

edge = []
for i in range(0, n-1):
	for j in range(i+1, n):
		p1 = planet[i]
		p2 = planet[j]
		d = (p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2
		if(p1[2] != p2[2]):
			r1 = p1[0] ** 2 + p1[1] ** 2
			r2 = p2[0] ** 2 + p2[1] ** 2
			d = r1 + r2 - isqrt(4 * r1 * r2)
		edge.append((i, j, d))
edge.sort(key = lambda x : x[2])

uni = UnionFind(n)
ans = 0
for a, b, c in edge:
	ans = c
	uni.unite(a, b)
	if(uni.same(0, n-1)):
		break

print(ans)
0