結果
問題 | No.2290 UnUnion Find |
ユーザー | yas_yasyu |
提出日時 | 2023-05-05 21:58:50 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,505 bytes |
コンパイル時間 | 232 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 26,600 KB |
最終ジャッジ日時 | 2024-11-23 07:33:09 |
合計ジャッジ時間 | 115,165 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
23,168 KB |
testcase_01 | AC | 36 ms
18,452 KB |
testcase_02 | TLE | - |
testcase_03 | TLE | - |
testcase_04 | TLE | - |
testcase_05 | TLE | - |
testcase_06 | TLE | - |
testcase_07 | TLE | - |
testcase_08 | TLE | - |
testcase_09 | TLE | - |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | AC | 1,423 ms
20,244 KB |
testcase_20 | AC | 1,363 ms
26,600 KB |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | TLE | - |
testcase_24 | AC | 1,359 ms
20,888 KB |
testcase_25 | TLE | - |
testcase_26 | AC | 1,351 ms
21,400 KB |
testcase_27 | AC | 1,369 ms
21,140 KB |
testcase_28 | AC | 1,621 ms
19,864 KB |
testcase_29 | AC | 1,375 ms
25,972 KB |
testcase_30 | TLE | - |
testcase_31 | AC | 1,373 ms
25,960 KB |
testcase_32 | TLE | - |
testcase_33 | AC | 1,413 ms
25,448 KB |
testcase_34 | AC | 1,342 ms
21,784 KB |
testcase_35 | AC | 1,335 ms
21,400 KB |
testcase_36 | TLE | - |
testcase_37 | TLE | - |
testcase_38 | TLE | - |
testcase_39 | TLE | - |
testcase_40 | AC | 1,362 ms
14,196 KB |
testcase_41 | TLE | - |
testcase_42 | AC | 1,537 ms
13,556 KB |
testcase_43 | AC | 1,381 ms
13,312 KB |
testcase_44 | TLE | - |
testcase_45 | AC | 1,744 ms
12,408 KB |
testcase_46 | TLE | - |
ソースコード
import types _atcoder_code = """ # Python port of AtCoder Library. __version__ = '0.0.1' """ atcoder = types.ModuleType('atcoder') exec(_atcoder_code, atcoder.__dict__) _atcoder_dsu_code = """ import typing class DSU: ''' Implement (union by size) + (path halving) Reference: Zvi Galil and Giuseppe F. Italiano, Data structures and algorithms for disjoint set union problems ''' def __init__(self, n: int = 0) -> None: self._n = n self.parent_or_size = [-1] * n def merge(self, a: int, b: int) -> int: assert 0 <= a < self._n assert 0 <= b < self._n x = self.leader(a) y = self.leader(b) if x == y: return x if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x self.parent_or_size[x] += self.parent_or_size[y] self.parent_or_size[y] = x return x def same(self, a: int, b: int) -> bool: assert 0 <= a < self._n assert 0 <= b < self._n return self.leader(a) == self.leader(b) def leader(self, a: int) -> int: assert 0 <= a < self._n parent = self.parent_or_size[a] while parent >= 0: if self.parent_or_size[parent] < 0: return parent self.parent_or_size[a], a, parent = ( self.parent_or_size[parent], self.parent_or_size[parent], self.parent_or_size[self.parent_or_size[parent]] ) return a def size(self, a: int) -> int: assert 0 <= a < self._n return -self.parent_or_size[self.leader(a)] def groups(self) -> typing.List[typing.List[int]]: leader_buf = [self.leader(i) for i in range(self._n)] result: typing.List[typing.List[int]] = [[] for _ in range(self._n)] for i in range(self._n): result[leader_buf[i]].append(i) return list(filter(lambda r: r, result)) """ atcoder.dsu = types.ModuleType('atcoder.dsu') exec(_atcoder_dsu_code, atcoder.dsu.__dict__) dsu = atcoder.dsu # from atcoder import dsu N, Q = map(int, input().split()) G = dsu.DSU(N) for _ in range(Q): query, *args = map(int, input().split()) if query == 1: u, v = map(lambda x: x - 1, args) G.merge(u, v) if query == 2: for i in range(N): v = args[0] - 1 if not G.same(v, i): print(i + 1) break else: print(-1)