library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub rainbou-kpr/library

:heavy_check_mark: test/yosupo-unionfind.test.py

Depends on

Code

# verification-helper: PROBLEM https://judge.yosupo.jp/problem/unionfind
from py.unionfind import UnionFind


def main():
    N, Q = map(int, input().split())
    g = UnionFind(N)
    for i in range(Q):
        t, u, v = map(int, input().split())
        if t == 0:
            g.merge(u, v)
        else:
            print(1 if g.same(u, v) else 0)


if __name__ == "__main__":
    main()
Back to top page