# 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 | AC | 23 ms | 9 MB |
Python | max_random_00 | AC | 299 ms | 15 MB |
Python | max_random_01 | AC | 299 ms | 17 MB |
Python | max_random_02 | AC | 277 ms | 12 MB |
Python | path_00 | AC | 243 ms | 19 MB |
Python | path_01 | AC | 243 ms | 19 MB |
Python | path_02 | AC | 259 ms | 19 MB |
Python | path_03 | AC | 258 ms | 19 MB |
Python | random_00 | AC | 217 ms | 16 MB |
Python | random_01 | AC | 218 ms | 16 MB |
Python | random_02 | AC | 176 ms | 12 MB |
Python | random_03 | AC | 57 ms | 17 MB |
Python | random_04 | AC | 142 ms | 10 MB |
Python | random_05 | AC | 198 ms | 12 MB |
Python | random_06 | AC | 156 ms | 19 MB |
Python | random_07 | AC | 38 ms | 14 MB |
Python | random_08 | AC | 82 ms | 10 MB |
Python | random_09 | AC | 285 ms | 14 MB |