:heavy_check_mark: examples/python/union_find.yosupo.py

Depends on

Code

# 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()

Test cases

Env Name Status Elapsed Memory
Python example_00 :heavy_check_mark: AC 19 ms 11 MB
Python max_random_00 :heavy_check_mark: AC 305 ms 17 MB
Python max_random_01 :heavy_check_mark: AC 316 ms 18 MB
Python max_random_02 :heavy_check_mark: AC 266 ms 13 MB
Python path_00 :heavy_check_mark: AC 249 ms 20 MB
Python path_01 :heavy_check_mark: AC 251 ms 20 MB
Python path_02 :heavy_check_mark: AC 249 ms 20 MB
Python path_03 :heavy_check_mark: AC 258 ms 20 MB
Python random_00 :heavy_check_mark: AC 235 ms 17 MB
Python random_01 :heavy_check_mark: AC 238 ms 18 MB
Python random_02 :heavy_check_mark: AC 170 ms 13 MB
Python random_03 :heavy_check_mark: AC 60 ms 18 MB
Python random_04 :heavy_check_mark: AC 133 ms 11 MB
Python random_05 :heavy_check_mark: AC 196 ms 13 MB
Python random_06 :heavy_check_mark: AC 192 ms 20 MB
Python random_07 :heavy_check_mark: AC 39 ms 15 MB
Python random_08 :heavy_check_mark: AC 75 ms 11 MB
Python random_09 :heavy_check_mark: AC 290 ms 16 MB
Back to top page