Submission #11236305


Source Code Expand

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
import sys
input=sys.stdin.readline
n,m = map(int, input().split())
uf = UnionFind(m)
lang=set()
for i in range(n):
    lis = list(map(int,input().split()))
    for i in range(1,len(lis)-1):
        lang.add(lis[i]-1)
        uf.union(lis[i]-1,lis[i+1]-1)
    lang.add(lis[-1]-1)
e = next(iter(lang))
if lang == set(uf.members(e)):
    print("YES")
else:
    print("NO")

Submission Info

Submission Time
Task C - Interpretation
User s_shohei
Language PyPy3 (2.4.0)
Score 400
Code Size 1355 Byte
Status AC
Exec Time 509 ms
Memory 70764 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 164 ms 38384 KB
01-02.txt AC 198 ms 40944 KB
01-03.txt AC 175 ms 38768 KB
01-04.txt AC 176 ms 38768 KB
01-05.txt AC 176 ms 38768 KB
01-06.txt AC 179 ms 39408 KB
01-07.txt AC 179 ms 39280 KB
01-08.txt AC 178 ms 39152 KB
01-09.txt AC 179 ms 39408 KB
01-10.txt AC 175 ms 38768 KB
02-01.txt AC 334 ms 59996 KB
02-02.txt AC 307 ms 45276 KB
02-03.txt AC 333 ms 57052 KB
02-04.txt AC 483 ms 68952 KB
02-05.txt AC 402 ms 56284 KB
02-06.txt AC 509 ms 70764 KB
02-07.txt AC 370 ms 52572 KB
02-08.txt AC 248 ms 40940 KB
02-09.txt AC 260 ms 41836 KB
02-10.txt AC 254 ms 53616 KB
02-11.txt AC 257 ms 54876 KB
02-12.txt AC 266 ms 52060 KB
02-13.txt AC 268 ms 51804 KB
sample-01.txt AC 165 ms 38256 KB
sample-02.txt AC 163 ms 38256 KB