def test_groups(self) -> None: dsu = DSU(5) dsu.merge(0, 1) dsu.merge(0, 2) assert dsu.groups() == [[0, 1, 2], [3], [4]]
def main(): n, m = list(map(int, input().strip().split())) tree = DSU(n) for i in range(m): a, b = list(map(int, input().strip().split())) a = a - 1 b = b - 1 if a >= b: tree.merge(a, b) print(len(tree.groups()))
def test_initial_status(self) -> None: dsu = DSU(5) for i, j in combinations(range(5), 2): assert not dsu.same(i, j) for index in range(5): assert dsu.size(index) == 1 assert dsu.leader(index) == index assert dsu.groups() == [[0], [1], [2], [3], [4]]
def main(): n, m = list(map(int, input().strip().split())) tree = DSU(n) for _ in range(m): a, b = list(map(int, input().strip().split())) tree.merge(a - 1, b - 1) result = 0 for g in tree.groups(): result = max(result, len(g)) print(result)
def main(): n, q = list(map(int, input().strip().split())) tree = DSU(n) for _ in range(q): t, v1, v2 = list(map(int, input().strip().split())) if t == 0: tree.merge(v1, v2) if t == 1: if tree.same(v1, v2): print(1) else: print(0) num_of_groups = len(tree.groups())