提出 #42043337


ソースコード 拡げる

# 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
言語 PyPy3 (7.3.0)
得点 300
コード長 2381 Byte
結果 AC
実行時間 180 ms
メモリ 78512 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 3
AC × 38
セット名 テストケース
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 109 ms 74992 KiB
sample01.txt AC 89 ms 74828 KiB
sample02.txt AC 88 ms 74920 KiB
testcase00.txt AC 91 ms 75100 KiB
testcase01.txt AC 147 ms 77484 KiB
testcase02.txt AC 157 ms 78444 KiB
testcase03.txt AC 147 ms 77592 KiB
testcase04.txt AC 163 ms 78036 KiB
testcase05.txt AC 158 ms 78512 KiB
testcase06.txt AC 158 ms 78436 KiB
testcase07.txt AC 154 ms 78024 KiB
testcase08.txt AC 157 ms 78408 KiB
testcase09.txt AC 159 ms 78232 KiB
testcase10.txt AC 157 ms 77976 KiB
testcase11.txt AC 155 ms 78416 KiB
testcase12.txt AC 160 ms 77816 KiB
testcase13.txt AC 160 ms 78116 KiB
testcase14.txt AC 171 ms 78228 KiB
testcase15.txt AC 155 ms 78128 KiB
testcase16.txt AC 156 ms 77884 KiB
testcase17.txt AC 155 ms 78016 KiB
testcase18.txt AC 160 ms 77772 KiB
testcase19.txt AC 153 ms 78108 KiB
testcase20.txt AC 154 ms 77888 KiB
testcase21.txt AC 156 ms 78116 KiB
testcase22.txt AC 160 ms 77772 KiB
testcase23.txt AC 160 ms 77968 KiB
testcase24.txt AC 156 ms 77428 KiB
testcase25.txt AC 145 ms 77116 KiB
testcase26.txt AC 152 ms 77964 KiB
testcase27.txt AC 167 ms 77892 KiB
testcase28.txt AC 164 ms 78052 KiB
testcase29.txt AC 167 ms 77880 KiB
testcase30.txt AC 163 ms 78120 KiB
testcase31.txt AC 158 ms 78264 KiB
testcase32.txt AC 157 ms 78012 KiB
testcase33.txt AC 180 ms 78280 KiB
testcase34.txt AC 161 ms 77912 KiB