# competitive-verifier: PROBLEM https://judge.yosupo.jp/problem/unionfind
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 | example_00 |
![]() |
22 ms | 10 MB |
Python | max_random_00 |
![]() |
255 ms | 17 MB |
Python | max_random_01 |
![]() |
258 ms | 18 MB |
Python | max_random_02 |
![]() |
244 ms | 13 MB |
Python | path_00 |
![]() |
227 ms | 20 MB |
Python | path_01 |
![]() |
213 ms | 20 MB |
Python | path_02 |
![]() |
201 ms | 20 MB |
Python | path_03 |
![]() |
205 ms | 20 MB |
Python | random_00 |
![]() |
196 ms | 17 MB |
Python | random_01 |
![]() |
193 ms | 18 MB |
Python | random_02 |
![]() |
159 ms | 13 MB |
Python | random_03 |
![]() |
55 ms | 18 MB |
Python | random_04 |
![]() |
131 ms | 11 MB |
Python | random_05 |
![]() |
185 ms | 13 MB |
Python | random_06 |
![]() |
150 ms | 20 MB |
Python | random_07 |
![]() |
38 ms | 15 MB |
Python | random_08 |
![]() |
75 ms | 11 MB |
Python | random_09 |
![]() |
252 ms | 16 MB |