Submission #7698221


Source Code Expand

# cf16-finalC - Interpretation
class UnionFind:
    def __init__(self, size):
        self.parent = [i for i in range(size + 1)]
        self.rank = [0] * (size + 1)

    def find(self, x):
        if self.parent[x] == x:
            return x
        self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1


def main():
    N, M = map(int, input().split())
    A = [(map(int, input().split())) for _ in range(N)]
    uf, spoken = UnionFind(M), set()
    for _, *langs in A:
        spoken.update(langs)
        primary = langs[0]
        for l in langs[1:]:
            uf.unite(primary, l)
    cur = uf.find(spoken.pop())
    flg = all(uf.find(lang) == cur for lang in spoken)
    print("YES" if flg else "NO")


if __name__ == "__main__":
    main()

Submission Info

Submission Time
Task C - Interpretation
User solzard
Language Python (3.4.3)
Score 400
Code Size 1111 Byte
Status AC
Exec Time 371 ms
Memory 48104 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 17 ms 3064 KB
01-02.txt AC 19 ms 3188 KB
01-03.txt AC 21 ms 3444 KB
01-04.txt AC 20 ms 3316 KB
01-05.txt AC 20 ms 3316 KB
01-06.txt AC 21 ms 3316 KB
01-07.txt AC 20 ms 3316 KB
01-08.txt AC 20 ms 3316 KB
01-09.txt AC 21 ms 3312 KB
01-10.txt AC 21 ms 3444 KB
02-01.txt AC 234 ms 18476 KB
02-02.txt AC 367 ms 42296 KB
02-03.txt AC 203 ms 17608 KB
02-04.txt AC 346 ms 35312 KB
02-05.txt AC 334 ms 37020 KB
02-06.txt AC 352 ms 35396 KB
02-07.txt AC 352 ms 40480 KB
02-08.txt AC 354 ms 37756 KB
02-09.txt AC 371 ms 48104 KB
02-10.txt AC 256 ms 29284 KB
02-11.txt AC 241 ms 28968 KB
02-12.txt AC 276 ms 31052 KB
02-13.txt AC 266 ms 31072 KB
sample-01.txt AC 17 ms 3064 KB
sample-02.txt AC 17 ms 3064 KB