提出 #42044285


ソースコード 拡げる

# UnionFind
########################################
# https://github.com/not522/ac-library-python/blob/master/atcoder/dsu.py
# thx: not522-san
import typing
class DSU:
    '''
    Implement (union by size) + (path halving)

    Reference:
    Zvi Galil and Giuseppe F. Italiano,
    Data structures and algorithms for disjoint set union problems
    '''

    def __init__(self, n: int = 0) -> None:
        self._n = n
        self.parent_or_size = [-1] * n
    def merge(self, a: int, b: int) -> int:
        assert 0 <= a < self._n
        assert 0 <= b < self._n
        x = self.leader(a)
        y = self.leader(b)
        if x == y:
            return x
        if -self.parent_or_size[x] < -self.parent_or_size[y]:
            x, y = y, x
        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x
        return x
    def same(self, a: int, b: int) -> bool:
        assert 0 <= a < self._n
        assert 0 <= b < self._n
        return self.leader(a) == self.leader(b)
    def leader(self, a: int) -> int:
        assert 0 <= a < self._n
        parent = self.parent_or_size[a]
        while parent >= 0:
            if self.parent_or_size[parent] < 0:
                return parent
            self.parent_or_size[a], a, parent = (
                self.parent_or_size[parent],
                self.parent_or_size[parent],
                self.parent_or_size[self.parent_or_size[parent]]
            )
        return a
    def size(self, a: int) -> int:
        assert 0 <= a < self._n
        return -self.parent_or_size[self.leader(a)]
    def groups(self) -> typing.List[typing.List[int]]:
        leader_buf = [self.leader(i) for i in range(self._n)]
        result: typing.List[typing.List[int]] = [[] for _ in range(self._n)]
        for i in range(self._n):
            result[leader_buf[i]].append(i)
        return list(filter(lambda r: r, result))
########################################
from collections import deque
n, d = map(int, input().split())
dat = []
for _ in range(n): dat.append(tuple(map(int, input().split())))
dsu = DSU(n)
for i in range(n):
    x1, y1 = dat[i]
    for j in range(i+1, n):
        x2, y2 = dat[j]
        if (x1-x2)**2 + (y1-y2)**2 <= (d**2):
            dsu.merge(i, j)
for i in range(n): print("Yes" if dsu.same(0, i) else "No")

提出情報

提出日時
問題 C - Virus
ユーザ recuraki
言語 Python (3.8.2)
得点 0
コード長 2381 Byte
結果 TLE
実行時間 2206 ms
メモリ 10388 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 300
結果
AC × 3
AC × 36
TLE × 2
セット名 テストケース
Sample sample00.txt, sample01.txt, sample02.txt
All sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt, testcase34.txt
ケース名 結果 実行時間 メモリ
sample00.txt AC 36 ms 10064 KiB
sample01.txt AC 27 ms 10132 KiB
sample02.txt AC 28 ms 10164 KiB
testcase00.txt AC 31 ms 10168 KiB
testcase01.txt AC 1379 ms 10172 KiB
testcase02.txt AC 1413 ms 10112 KiB
testcase03.txt AC 1409 ms 10144 KiB
testcase04.txt AC 1414 ms 10192 KiB
testcase05.txt AC 1393 ms 10176 KiB
testcase06.txt AC 1550 ms 10200 KiB
testcase07.txt AC 1373 ms 10216 KiB
testcase08.txt AC 1547 ms 10092 KiB
testcase09.txt AC 1353 ms 10264 KiB
testcase10.txt AC 1539 ms 10096 KiB
testcase11.txt AC 1398 ms 10128 KiB
testcase12.txt AC 1556 ms 10300 KiB
testcase13.txt AC 1330 ms 10200 KiB
testcase14.txt AC 1569 ms 10084 KiB
testcase15.txt AC 1399 ms 10048 KiB
testcase16.txt AC 1533 ms 10144 KiB
testcase17.txt AC 1373 ms 10196 KiB
testcase18.txt AC 1563 ms 10208 KiB
testcase19.txt AC 1383 ms 10076 KiB
testcase20.txt AC 1569 ms 10380 KiB
testcase21.txt AC 1397 ms 10180 KiB
testcase22.txt AC 1558 ms 10188 KiB
testcase23.txt AC 1400 ms 10152 KiB
testcase24.txt AC 1552 ms 10092 KiB
testcase25.txt AC 1502 ms 10084 KiB
testcase26.txt AC 1315 ms 10300 KiB
testcase27.txt AC 1577 ms 10088 KiB
testcase28.txt AC 1549 ms 10188 KiB
testcase29.txt AC 1539 ms 10092 KiB
testcase30.txt AC 1554 ms 10072 KiB
testcase31.txt AC 1344 ms 10188 KiB
testcase32.txt AC 1485 ms 10388 KiB
testcase33.txt TLE 2206 ms 10360 KiB
testcase34.txt TLE 2206 ms 10356 KiB