Submission #11232011


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 731 ms
Memory 78040 KB

Judge Result

Set Name sample dataset1 dataset2
Score / Max Score 0 / 0 0 / 200 0 / 200
Status
AC × 2
AC × 10
WA × 2
AC × 20
WA × 7
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 160 ms 38256 KB
01-02.txt AC 170 ms 39024 KB
01-03.txt WA 196 ms 39152 KB
01-04.txt AC 199 ms 39152 KB
01-05.txt AC 194 ms 39152 KB
01-06.txt AC 183 ms 38640 KB
01-07.txt AC 186 ms 39152 KB
01-08.txt WA 183 ms 38640 KB
01-09.txt AC 188 ms 38896 KB
01-10.txt AC 197 ms 39152 KB
02-01.txt AC 421 ms 59992 KB
02-02.txt WA 609 ms 61528 KB
02-03.txt AC 449 ms 60248 KB
02-04.txt AC 731 ms 78040 KB
02-05.txt AC 620 ms 66520 KB
02-06.txt WA 641 ms 71640 KB
02-07.txt AC 671 ms 66776 KB
02-08.txt WA 556 ms 57560 KB
02-09.txt AC 573 ms 66264 KB
02-10.txt AC 502 ms 66796 KB
02-11.txt WA 497 ms 66304 KB
02-12.txt AC 509 ms 62424 KB
02-13.txt WA 507 ms 61400 KB
sample-01.txt AC 159 ms 38256 KB
sample-02.txt AC 161 ms 38256 KB