Submission #11231940


Source Code Expand

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.p = [e for e in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    def same(self, u, v):
        return self.find_set(u) == self.find_set(v)

    def unite(self, u, v):
        u = self.find_set(u)
        v = self.find_set(v)

        if u == v:
            return

        if self.rank[u] > self.rank[v]:
            self.p[v] = u
            self.size[u] += self.size[v]
        else:
            self.p[u] = v
            self.size[v] += self.size[u]
            if self.rank[u] == self.rank[v]:
                self.rank[v] += 1

    def find_set(self, u):
        if u != self.p[u]:
            self.p[u] = self.find_set(self.p[u])

        return self.p[u]

    def update_p(self):
        for u in range(self.n):
            self.find_set(u)

    def get_size(self, u):
        return self.size[self.find_set(u)]


n, m = map(int, input().split())
l = []
for _ in range(n):
    k, *ls = map(int, input().split())
    l.append(ls)

uf = UnionFind(m)

cnt = [0] * m
for li in l:
    for e1, e2 in zip(li, li[1:]):
        e1 -= 1
        e2 -= 1
        cnt[e1] = 1
        cnt[e2] = 1
        uf.unite(e1, e2)

if max(uf.size) == sum(cnt):
    ans = "YES"
else:
    ans = "NO"

print(ans)

Submission Info

Submission Time
Task C - Interpretation
User shamio
Language PyPy3 (2.4.0)
Score 0
Code Size 1355 Byte
Status WA
Exec Time 737 ms
Memory 78040 KB

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 0 / 200 0 / 200
Status
AC × 2
AC × 9
WA × 3
AC × 19
WA × 8
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 WA 171 ms 38384 KB
01-02.txt AC 200 ms 39920 KB
01-03.txt AC 213 ms 39664 KB
01-04.txt AC 207 ms 39152 KB
01-05.txt AC 201 ms 39152 KB
01-06.txt AC 191 ms 38640 KB
01-07.txt AC 195 ms 39152 KB
01-08.txt WA 193 ms 38640 KB
01-09.txt AC 195 ms 38768 KB
01-10.txt WA 204 ms 39152 KB
02-01.txt AC 443 ms 60632 KB
02-02.txt WA 614 ms 61528 KB
02-03.txt AC 469 ms 60248 KB
02-04.txt AC 737 ms 78040 KB
02-05.txt AC 657 ms 66520 KB
02-06.txt WA 651 ms 71640 KB
02-07.txt AC 693 ms 66776 KB
02-08.txt AC 566 ms 57560 KB
02-09.txt WA 648 ms 66392 KB
02-10.txt AC 521 ms 66796 KB
02-11.txt WA 517 ms 66304 KB
02-12.txt AC 516 ms 62424 KB
02-13.txt WA 516 ms 61400 KB
sample-01.txt AC 167 ms 38256 KB
sample-02.txt AC 167 ms 38256 KB