結果
問題 | No.2179 Planet Traveler |
ユーザー | MasKoaTS |
提出日時 | 2022-08-02 21:49:47 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 663 ms / 3,000 ms |
コード長 | 1,474 bytes |
コンパイル時間 | 361 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 128,316 KB |
最終ジャッジ日時 | 2024-05-07 20:26:08 |
合計ジャッジ時間 | 10,891 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
52,608 KB |
testcase_01 | AC | 35 ms
52,480 KB |
testcase_02 | AC | 35 ms
52,736 KB |
testcase_03 | AC | 34 ms
52,608 KB |
testcase_04 | AC | 37 ms
52,224 KB |
testcase_05 | AC | 36 ms
52,736 KB |
testcase_06 | AC | 37 ms
52,736 KB |
testcase_07 | AC | 37 ms
52,608 KB |
testcase_08 | AC | 44 ms
59,008 KB |
testcase_09 | AC | 44 ms
59,776 KB |
testcase_10 | AC | 45 ms
58,880 KB |
testcase_11 | AC | 549 ms
125,404 KB |
testcase_12 | AC | 575 ms
123,580 KB |
testcase_13 | AC | 594 ms
125,756 KB |
testcase_14 | AC | 570 ms
127,924 KB |
testcase_15 | AC | 563 ms
128,316 KB |
testcase_16 | AC | 560 ms
127,676 KB |
testcase_17 | AC | 618 ms
125,980 KB |
testcase_18 | AC | 663 ms
126,472 KB |
testcase_19 | AC | 590 ms
125,392 KB |
testcase_20 | AC | 128 ms
83,456 KB |
testcase_21 | AC | 581 ms
126,884 KB |
testcase_22 | AC | 385 ms
104,528 KB |
testcase_23 | AC | 315 ms
103,048 KB |
testcase_24 | AC | 485 ms
113,788 KB |
testcase_25 | AC | 387 ms
106,000 KB |
testcase_26 | AC | 493 ms
117,804 KB |
testcase_27 | AC | 121 ms
83,968 KB |
testcase_28 | AC | 258 ms
95,572 KB |
testcase_29 | AC | 510 ms
114,208 KB |
ソースコード
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)