結果

問題 No.94 圏外です。(EASY)
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-03-09 13:19:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 642 ms / 5,000 ms
コード長 1,732 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 11,336 KB
実行使用メモリ 9,236 KB
最終ジャッジ日時 2023-09-08 14:48:34
合計ジャッジ時間 6,488 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,904 KB
testcase_01 AC 20 ms
9,060 KB
testcase_02 AC 19 ms
9,008 KB
testcase_03 AC 19 ms
9,064 KB
testcase_04 AC 23 ms
9,016 KB
testcase_05 AC 33 ms
9,060 KB
testcase_06 AC 58 ms
9,000 KB
testcase_07 AC 108 ms
8,952 KB
testcase_08 AC 208 ms
9,156 KB
testcase_09 AC 404 ms
9,048 KB
testcase_10 AC 404 ms
9,128 KB
testcase_11 AC 391 ms
9,180 KB
testcase_12 AC 409 ms
9,172 KB
testcase_13 AC 407 ms
9,236 KB
testcase_14 AC 420 ms
9,108 KB
testcase_15 AC 404 ms
9,216 KB
testcase_16 AC 410 ms
9,216 KB
testcase_17 AC 422 ms
9,208 KB
testcase_18 AC 413 ms
9,128 KB
testcase_19 AC 642 ms
9,168 KB
testcase_20 AC 19 ms
8,868 KB
testcase_21 AC 19 ms
8,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
import collections
import itertools


EPS = 10 ** (-9)


Station = collections.namedtuple("Station", "index coordinate")


class UnionFind(object):

    def __init__(self, number_of_nodes):
        self.par = array.array("L", range(number_of_nodes))
        self.rank = array.array("L", (0 for i in range(number_of_nodes)))

    def root(self, node):
        if self.par[node] == node:
            return node
        else:
            r = self.root(self.par[node])
            self.par[node] = r
            return r

    def in_the_same_set(self, node1, node2):
        return self.root(node1) == self.root(node2)

    def unite(self, node1, node2):
        x = self.root(node1)
        y = self.root(node2)
        if x == y:
            pass
        elif self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1


def main():
    n = int(input())
    if n == 0:
        print("{:.12f}".format(1.0))
        return
    elif n == 1:
        print("{:.12f}".format(2.0))
        return
    stations = [Station(i, complex(*map(int, input().split())))
                for i in range(n)]
    uf = UnionFind(n)
    for st1, st2 in itertools.combinations(stations, 2):
        if abs(st1.coordinate - st2.coordinate) < 10.0 + EPS:
            uf.unite(st1.index, st2.index)
    answer = 2.0
    for st1, st2 in itertools.combinations(stations, 2):
        if uf.in_the_same_set(st1.index, st2.index):
            answer = max(answer, 2.0 + abs(st1.coordinate - st2.coordinate))
    print("{:.12f}".format(answer))


if __name__ == '__main__':
    main()
0