CODE FESTIVAL 2016 Final

Submission #5889724

Source codeソースコード

n, m = [int(item) for item in input().split()]
query = []
appeared = set()
for i in range(n):
    line = [int(item) for item in input().split()]
    appeared.update(line[1:])
    query.append(line[1:])
    
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.size = [1] * n
        self.rank = [0] * n

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

    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        return self.size[self.find(x)]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

uf = UnionFind(m)
for q in query:
    if len(q) == 1:
        continue
    for item in q[1:]:
        if not uf.same_check(q[0]-1, item-1):
            uf.union(q[0]-1, item-1)
    
par = uf.find(appeared.pop() - 1)
for item in appeared:
    if uf.find(item - 1) != par:
        print("NO")
        exit()
print("YES")

Submission

Task問題 C - Interpretation
User nameユーザ名 nagitaosu
Created time投稿日時
Language言語 Python3 (3.4.3)
Status状態 AC
Score得点 400
Source lengthソースコード長 1298 Byte
File nameファイル名
Exec time実行時間 418 ms
Memory usageメモリ使用量 22036 KB

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt
dataset1 200 / 200 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 200 / 200 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 18 ms 3064 KB
01-02.txt AC 20 ms 3188 KB
01-03.txt AC 21 ms 3188 KB
01-04.txt AC 21 ms 3064 KB
01-05.txt AC 21 ms 3188 KB
01-06.txt AC 21 ms 3188 KB
01-07.txt AC 21 ms 3188 KB
01-08.txt AC 21 ms 3188 KB
01-09.txt AC 21 ms 3188 KB
01-10.txt AC 21 ms 3316 KB
02-01.txt AC 320 ms 14936 KB
02-02.txt AC 370 ms 15332 KB
02-03.txt AC 279 ms 12680 KB
02-04.txt AC 418 ms 19460 KB
02-05.txt AC 378 ms 15340 KB
02-06.txt AC 404 ms 19500 KB
02-07.txt AC 404 ms 16392 KB
02-08.txt AC 382 ms 13280 KB
02-09.txt AC 401 ms 22036 KB
02-10.txt AC 329 ms 16888 KB
02-11.txt AC 311 ms 16920 KB
02-12.txt AC 345 ms 16472 KB
02-13.txt AC 336 ms 16468 KB
sample-01.txt AC 18 ms 3064 KB
sample-02.txt AC 17 ms 3064 KB