結果

問題 No.94 圏外です。(EASY)
ユーザー matsu7874matsu7874
提出日時 2015-11-29 20:53:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,571 bytes
コンパイル時間 1,062 ms
コンパイル使用メモリ 11,016 KB
実行使用メモリ 32,824 KB
最終ジャッジ日時 2023-10-12 05:51:39
合計ジャッジ時間 9,742 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 17 ms
8,284 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

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())
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] <= 10:
            uf.union(i, j)
max_len = 1
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])
print(max_len)
0