Submission #7086288
Source Code Expand
import sys import heapq from operator import itemgetter from collections import deque, defaultdict from bisect import bisect_left, bisect_right input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) MOD = 10**9 + 7 class UnionFind : def __init__(self, size) : """ Parameters --- size : int 頂点数 """ self.parent = list(range(size)) self.height = [0] * size self.size = [1] * size self.component = size def root(self, index) : """ 親のインデックスの取得 Parameters --- index : int 取得する頂点のインデックス Returns --- rootIndex : int 指定した頂点の根のインデックス """ if self.parent[index] == index : # 根の場合 return index rootIndex = self.root(self.parent[index]) # 葉の場合親の根を取得 self.parent[index] = rootIndex # 親の付け直し return rootIndex def union(self, index1, index2) : # 結合 """ 木の結合 Parameters --- index1 : int index2 : int 結合する頂点のインデックス """ root1 = self.root(index1) root2 = self.root(index2) if root1 == root2 : # 連結されている場合 return self.component -= 1 # 連結成分を減らす if self.height[root1] < self.height[root2] : self.parent[root1] = root2 # root2に結合 self.size[root2] += self.size[root1] else : self.parent[root2] = root1 # root1に結合 self.size[root1] += self.size[root2] if self.height[root1] == self.height[root2] : self.height[root1] += 1 return def isSameRoot(self, index1, index2) : """ 同じ木に属するかを判定する Parameters --- index1 : int index2 : int Returns --- boolean """ return self.root(index1) == self.root(index2) def sizeOfSameRoot(self, index) : """ 指定した頂点の属する木の大きさを取得する """ return self.size[self.root(index)] def getComponent(self) : """ 連結成分数を取得する """ return self.component def sol(): N, M = map(int, input().split()) tree = UnionFind(N + M) for person in range(N): line = list(map(int, input().split())) for lang in line[1:]: tree.union(person, N + lang - 1) rootList = set() for person in range(N): rootList.add(tree.root(person)) if len(rootList) == 1: print('YES') else: print('NO') sol()
Submission Info
Submission Time | |
---|---|
Task | C - Interpretation |
User | OKCH3COOH |
Language | PyPy3 (2.4.0) |
Score | 400 |
Code Size | 2987 Byte |
Status | AC |
Exec Time | 512 ms |
Memory | 66924 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 | 169 ms | 38384 KB |
01-02.txt | AC | 177 ms | 39408 KB |
01-03.txt | AC | 185 ms | 39280 KB |
01-04.txt | AC | 186 ms | 39152 KB |
01-05.txt | AC | 191 ms | 39664 KB |
01-06.txt | AC | 187 ms | 39664 KB |
01-07.txt | AC | 189 ms | 40176 KB |
01-08.txt | AC | 188 ms | 39664 KB |
01-09.txt | AC | 189 ms | 39792 KB |
01-10.txt | AC | 188 ms | 39280 KB |
02-01.txt | AC | 319 ms | 52076 KB |
02-02.txt | AC | 337 ms | 48728 KB |
02-03.txt | AC | 343 ms | 54620 KB |
02-04.txt | AC | 482 ms | 63196 KB |
02-05.txt | AC | 441 ms | 57560 KB |
02-06.txt | AC | 512 ms | 66924 KB |
02-07.txt | AC | 410 ms | 54744 KB |
02-08.txt | AC | 277 ms | 44504 KB |
02-09.txt | AC | 288 ms | 46808 KB |
02-10.txt | AC | 272 ms | 50284 KB |
02-11.txt | AC | 273 ms | 51544 KB |
02-12.txt | AC | 273 ms | 47320 KB |
02-13.txt | AC | 271 ms | 46680 KB |
sample-01.txt | AC | 168 ms | 38256 KB |
sample-02.txt | AC | 172 ms | 38256 KB |