結果
問題 | No.2202 贅沢てりたまチキン |
ユーザー |
|
提出日時 | 2023-02-06 14:38:34 |
言語 | Python3 (3.11.2 + numpy 1.24.2 + scipy 1.10.1) |
結果 |
AC
|
実行時間 | 1,140 ms / 2,000 ms |
コード長 | 1,415 bytes |
コンパイル時間 | 139 ms |
コンパイル使用メモリ | 11,068 KB |
実行使用メモリ | 27,276 KB |
最終ジャッジ日時 | 2023-09-18 02:06:27 |
合計ジャッジ時間 | 15,784 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 17 ms
8,404 KB |
testcase_01 | AC | 16 ms
8,236 KB |
testcase_02 | AC | 17 ms
8,132 KB |
testcase_03 | AC | 16 ms
8,232 KB |
testcase_04 | AC | 17 ms
8,256 KB |
testcase_05 | AC | 15 ms
8,440 KB |
testcase_06 | AC | 16 ms
8,116 KB |
testcase_07 | AC | 16 ms
8,352 KB |
testcase_08 | AC | 15 ms
8,352 KB |
testcase_09 | AC | 15 ms
8,220 KB |
testcase_10 | AC | 52 ms
27,140 KB |
testcase_11 | AC | 16 ms
8,268 KB |
testcase_12 | AC | 15 ms
8,332 KB |
testcase_13 | AC | 16 ms
8,316 KB |
testcase_14 | AC | 933 ms
27,212 KB |
testcase_15 | AC | 925 ms
27,068 KB |
testcase_16 | AC | 865 ms
27,188 KB |
testcase_17 | AC | 996 ms
27,184 KB |
testcase_18 | AC | 441 ms
17,884 KB |
testcase_19 | AC | 447 ms
27,100 KB |
testcase_20 | AC | 975 ms
27,184 KB |
testcase_21 | AC | 977 ms
27,276 KB |
testcase_22 | AC | 762 ms
8,264 KB |
testcase_23 | AC | 769 ms
8,968 KB |
testcase_24 | AC | 740 ms
8,240 KB |
testcase_25 | AC | 1,140 ms
27,256 KB |
testcase_26 | AC | 1,046 ms
27,144 KB |
testcase_27 | AC | 925 ms
27,196 KB |
ソースコード
import sys sys.setrecursionlimit(20000) class UnionFindTree: def __init__(self, length: int) -> None: self.list = [idx for idx in range(length)] self.size = [1 for _ in range(length)] def get_root(self, idx: int) -> int: if self.list[idx] == idx: return idx self.list[idx] = self.get_root(self.list[idx]) return self.list[idx] def is_same(self, idx1: int, idx2: int) -> bool: return self.get_root(idx1) == self.get_root(idx2) def merge(self, idx1: int, idx2: int): if self.is_same(idx1, idx2): return idx1_root = self.get_root(idx1) idx2_root = self.get_root(idx2) if self.size[idx1_root] > self.size[idx2_root]: self.list[idx2_root] = idx1_root self.size[idx1_root] += self.size[idx2_root] else: self.list[idx1_root] = idx2_root self.size[idx2_root] += self.size[idx1_root] def get_size(self, idx: int) -> int: return self.size[self.get_root(idx)] def main(): N, M = map(int, input().split()) uft = UnionFindTree(2*N) for _ in range(M): A, B = map(lambda n: int(n)-1, input().split()) uft.merge(A*2, B*2+1) uft.merge(B*2, A*2+1) if all(uft.is_same(idx*2, idx*2+1) for idx in range(N)): print("Yes") else: print("No") if __name__ == "__main__": main()