# competitive-verifier: PROBLEM https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_1_A
import sys
input = sys.stdin.buffer.readline
from examples.python.union_find import UnionFind
def main() -> None:
N, Q = map(int, input().split())
uf = UnionFind(N)
for _ in range(Q):
t, u, v = map(int, input().split())
if t == 0:
uf.unite(u, v)
else:
print(int(uf.is_same(u, v)))
if __name__ == "__main__":
main()
Env | Name | Status | Elapsed | Memory |
---|---|---|---|---|
Python | 00_small_00.in | AC | 28 ms | 10 MB |
Python | 00_small_01.in | AC | 23 ms | 9 MB |
Python | 01_rand_00.in | AC | 24 ms | 9 MB |
Python | 01_rand_01.in | AC | 22 ms | 9 MB |
Python | 01_rand_02.in | AC | 22 ms | 9 MB |
Python | 01_rand_03.in | AC | 22 ms | 9 MB |
Python | 01_rand_04.in | AC | 23 ms | 9 MB |
Python | 01_rand_05.in | AC | 22 ms | 9 MB |
Python | 02_linear_00.in | AC | 22 ms | 9 MB |
Python | 02_linear_01.in | AC | 24 ms | 9 MB |
Python | 02_linear_02.in | AC | 33 ms | 9 MB |
Python | 02_linear_03.in | AC | 45 ms | 10 MB |
Python | 03_grid_00.in | AC | 22 ms | 9 MB |
Python | 03_grid_01.in | AC | 22 ms | 9 MB |
Python | 03_grid_02.in | AC | 23 ms | 9 MB |
Python | 03_grid_03.in | AC | 24 ms | 9 MB |
Python | 03_grid_04.in | AC | 22 ms | 9 MB |
Python | 03_grid_05.in | AC | 22 ms | 9 MB |
Python | 03_grid_06.in | AC | 22 ms | 9 MB |
Python | 03_grid_07.in | AC | 23 ms | 10 MB |
Python | 03_grid_08.in | AC | 23 ms | 10 MB |
Python | 04_critical_00.in | AC | 45 ms | 10 MB |
Python | 04_critical_01.in | AC | 45 ms | 10 MB |
Python | 05_groups_00.in | AC | 80 ms | 10 MB |
Python | 05_groups_01.in | AC | 80 ms | 10 MB |
Python | 05_groups_02.in | AC | 77 ms | 10 MB |
Python | 05_groups_03.in | AC | 79 ms | 10 MB |
Python | 05_groups_04.in | AC | 78 ms | 10 MB |
Python | 06_randmax_00.in | AC | 25 ms | 10 MB |
Python | 06_randmax_01.in | AC | 84 ms | 10 MB |
Python | 06_randmax_02.in | AC | 107 ms | 10 MB |
Python | 06_randmax_03.in | AC | 145 ms | 10 MB |