結果

問題 No.94 圏外です。(EASY)
ユーザー matsu7874matsu7874
提出日時 2015-11-29 20:59:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,612 bytes
コンパイル時間 130 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 37,568 KB
最終ジャッジ日時 2023-10-12 05:54:00
合計ジャッジ時間 16,967 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,144 KB
testcase_01 AC 16 ms
8,092 KB
testcase_02 AC 16 ms
8,160 KB
testcase_03 AC 16 ms
8,436 KB
testcase_04 AC 25 ms
8,624 KB
testcase_05 AC 43 ms
9,340 KB
testcase_06 AC 86 ms
11,368 KB
testcase_07 AC 183 ms
14,884 KB
testcase_08 AC 358 ms
21,296 KB
testcase_09 AC 851 ms
33,040 KB
testcase_10 AC 864 ms
33,148 KB
testcase_11 AC 743 ms
33,140 KB
testcase_12 AC 820 ms
32,944 KB
testcase_13 AC 807 ms
32,992 KB
testcase_14 AC 994 ms
33,076 KB
testcase_15 AC 843 ms
33,132 KB
testcase_16 AC 1,005 ms
33,028 KB
testcase_17 AC 956 ms
33,096 KB
testcase_18 AC 837 ms
33,016 KB
testcase_19 TLE -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:

    def __init__(self, size):
        # 負の値はルート (集合の代表) で集合の個数
        # 正の値は次の要素を表す
        self.table = [-1 for _ in range(size)]

    def search_group_ids(self):
        ids = []
        for t in self.table:
            if t > -1:
                ids.append(t)
        return ids

    def count_groups(self):
        cnt = 0
        for t in self.table:
            if t > -1:
                cnt += 1
        return cnt

    def find(self, x):
        # 集合の代表を求める
        while self.table[x] >= 0:
            x = self.table[x]
        return x

    def union(self, x, y):
        # 併合
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] >= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
        return self.table[s1]

N = int(input())
if N==0:
    print(1)
    exit()
P = []
for i in range(N):
    x, y = map(int, input().split())
    P.append((y, x))
uf = UnionFind(N)
dist = [[0 for j in range(N)] for i in range(N)]
for i in range(N - 1):
    for j in range(i + 1, N):
        dy = P[i][0] - P[j][0]
        dx = P[i][1] - P[j][1]
        dist[i][j] = dy * dy + dx * dx
        if dist[i][j] <= 100:
            uf.union(i, j)
max_len = 2
for i in range(N - 1):
    for j in range(i + 1, N):
        if uf.find(i) == uf.find(j):
            max_len = max(max_len, dist[i][j]**0.5+2)
print(max_len)
0