Submission #6434956


Source Code Expand

import sys
input = sys.stdin.readline


class UnionFindTree():
    def __init__(self, N):
        self.N = N
        self.__parent_of = [None] * N
        self.__rank_of = [0] * N
        self.__size = [1] * N

    def root(self, value):
        if self.__parent_of[value] is None:
            return value
        else:
            self.__parent_of[value] = self.root(self.__parent_of[value])
            return self.__parent_of[value]

    def unite(self, a, b):
        r1 = self.root(a)
        r2 = self.root(b)
        if r1 != r2:
            if self.__rank_of[r1] < self.__rank_of[r2]:
                self.__parent_of[r1] = r2
                self.__size[r2] += self.__size[r1]
            else:
                self.__parent_of[r2] = r1
                self.__size[r1] += self.__size[r2]
                if self.__rank_of[r1] == self.__rank_of[r2]:
                    self.__rank_of[r1] += 1

    def is_same(self, a, b):
        return self.root(a) == self.root(b)

    def size(self, a):
        return self.__size[self.root(a)]

    def groups(self):
        groups = {}
        for k in range(self.N):
            r = self.root(k)
            if r not in groups:
                groups[r] = []
            groups[r].append(k)
        return [groups[x] for x in groups]


def main():
    N, M = map(int, input().split())
    uft = UnionFindTree(N)
    speakers = [[] for _ in range(M)]
    for i in range(N):
        langs = list(map(int, input().split()))
        for l in langs[1:]:
            speakers[l-1].append(i)
    for i in range(M):
        for j in range(1, len(speakers[i])):
            uft.unite(speakers[i][j-1], speakers[i][j])
    if len(uft.groups()) == 1:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()

Submission Info

Submission Time
Task C - Interpretation
User blcn
Language PyPy3 (2.4.0)
Score 400
Code Size 1847 Byte
Status AC
Exec Time 594 ms
Memory 81056 KB

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 200 / 200 200 / 200
Status
AC × 2
AC × 12
AC × 27
Set Name Test Cases
sample sample-01.txt, sample-02.txt
dataset1 sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt
dataset2 sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, sample-01.txt, sample-02.txt
Case Name Status Exec Time Memory
01-01.txt AC 161 ms 38256 KB
01-02.txt AC 167 ms 38640 KB
01-03.txt AC 178 ms 39280 KB
01-04.txt AC 181 ms 39536 KB
01-05.txt AC 179 ms 39536 KB
01-06.txt AC 180 ms 39792 KB
01-07.txt AC 178 ms 39536 KB
01-08.txt AC 177 ms 39408 KB
01-09.txt AC 186 ms 39664 KB
01-10.txt AC 179 ms 39152 KB
02-01.txt AC 354 ms 61216 KB
02-02.txt AC 337 ms 58460 KB
02-03.txt AC 387 ms 59996 KB
02-04.txt AC 498 ms 73888 KB
02-05.txt AC 417 ms 64220 KB
02-06.txt AC 594 ms 81056 KB
02-07.txt AC 436 ms 65884 KB
02-08.txt AC 279 ms 54364 KB
02-09.txt AC 296 ms 59952 KB
02-10.txt AC 272 ms 57200 KB
02-11.txt AC 268 ms 58224 KB
02-12.txt AC 282 ms 55260 KB
02-13.txt AC 281 ms 56284 KB
sample-01.txt AC 162 ms 38256 KB
sample-02.txt AC 163 ms 38256 KB