結果
| 問題 |
No.94 圏外です。(EASY)
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-03-13 20:15:56 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 131 ms / 5,000 ms |
| コード長 | 1,547 bytes |
| コンパイル時間 | 393 ms |
| コンパイル使用メモリ | 82,556 KB |
| 実行使用メモリ | 77,228 KB |
| 最終ジャッジ日時 | 2024-11-22 16:58:30 |
| 合計ジャッジ時間 | 3,062 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#!/usr/bin/env python3.8
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools
# %%
N = int(readline())
m = map(int, read().split())
XY = tuple(zip(m, m))
# %%
def gen_edges():
for i, j in itertools.combinations(range(N), 2):
x1, y1 = XY[i]
x2, y2 = XY[j]
dx = x1 - x2
dy = y1 - y2
if dx * dx + dy * dy <= 100:
yield(i, j)
# %%
class UnionFind:
def __init__(self, N):
self.root = list(range(N))
self.size = [1] * (N)
def find_root(self, x):
root = self.root
while root[x] != x:
root[x] = root[root[x]]
x = root[x]
return x
def merge(self, x, y):
x = self.find_root(x)
y = self.find_root(y)
if x == y:
return False
sx, sy = self.size[x], self.size[y]
if sx < sy:
self.root[x] = y
self.size[y] += sx
else:
self.root[y] = x
self.size[x] += sy
return True
# %%
uf = UnionFind(N)
for i, j in gen_edges():
uf.merge(i, j)
# %%
root = [uf.find_root(i) for i in range(N)]
def gen_dist():
for i, j in itertools.combinations(range(N), 2):
if root[i] == root[j]:
x1, y1 = XY[i]
x2, y2 = XY[j]
dx = x1 - x2
dy = y1 - y2
yield (dx * dx + dy * dy) ** .5
# %%
answer = max(gen_dist(), default=0) + 2
if N == 0:
answer = 1
print(answer)
maspy