Submission #7698194
Source Code Expand
# cf16-finalC - Interpretation class UnionFind: # O(α(N)) def __init__(self, size): # construct a Union-Find tree (1-idx) self.parent = [i for i in range(size + 1)] self.rank = [0] * (size + 1) def find(self, x): # find the group (root) of a vertex if self.parent[x] == x: return x self.parent[x] = self.find(self.parent[x]) return self.parent[x] def unite(self, x, y): # unite two groups x, y = self.find(x), self.find(y) if x == y: # in the same group return # unite a small one to a bigger one to balance trees 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(): # Union-Find on spoken languages -> check all langs are in the same group? N, M = map(int, input().split()) A = tuple(tuple(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()) # group of one of spoken languages 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 | 1428 Byte |
Status | AC |
Exec Time | 360 ms |
Memory | 18116 KB |
Judge Result
Set Name | sample | dataset1 | dataset2 | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 200 / 200 | 200 / 200 | ||||||
Status |
|
|
|
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 | 18 ms | 3064 KB |
01-02.txt | AC | 20 ms | 3064 KB |
01-03.txt | AC | 21 ms | 3188 KB |
01-04.txt | AC | 21 ms | 3064 KB |
01-05.txt | AC | 21 ms | 3064 KB |
01-06.txt | AC | 21 ms | 3188 KB |
01-07.txt | AC | 21 ms | 3064 KB |
01-08.txt | AC | 21 ms | 3188 KB |
01-09.txt | AC | 21 ms | 3064 KB |
01-10.txt | AC | 21 ms | 3188 KB |
02-01.txt | AC | 258 ms | 14800 KB |
02-02.txt | AC | 343 ms | 12536 KB |
02-03.txt | AC | 219 ms | 12732 KB |
02-04.txt | AC | 359 ms | 17832 KB |
02-05.txt | AC | 336 ms | 13112 KB |
02-06.txt | AC | 356 ms | 17876 KB |
02-07.txt | AC | 360 ms | 13784 KB |
02-08.txt | AC | 335 ms | 10300 KB |
02-09.txt | AC | 350 ms | 18116 KB |
02-10.txt | AC | 278 ms | 15544 KB |
02-11.txt | AC | 256 ms | 15540 KB |
02-12.txt | AC | 284 ms | 15120 KB |
02-13.txt | AC | 276 ms | 15140 KB |
sample-01.txt | AC | 18 ms | 3064 KB |
sample-02.txt | AC | 18 ms | 3064 KB |