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

Depends on

Code

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

Test cases

Env Name Status Elapsed Memory
Python 00_small_00 :heavy_check_mark: AC 18 ms 10 MB
Python 00_small_01 :heavy_check_mark: AC 18 ms 10 MB
Python 01_rand_00 :heavy_check_mark: AC 18 ms 10 MB
Python 01_rand_01 :heavy_check_mark: AC 18 ms 10 MB
Python 01_rand_02 :heavy_check_mark: AC 18 ms 10 MB
Python 01_rand_03 :heavy_check_mark: AC 18 ms 10 MB
Python 01_rand_04 :heavy_check_mark: AC 19 ms 10 MB
Python 01_rand_05 :heavy_check_mark: AC 18 ms 10 MB
Python 02_linear_00 :heavy_check_mark: AC 18 ms 10 MB
Python 02_linear_01 :heavy_check_mark: AC 20 ms 10 MB
Python 02_linear_02 :heavy_check_mark: AC 28 ms 11 MB
Python 02_linear_03 :heavy_check_mark: AC 39 ms 11 MB
Python 03_grid_00 :heavy_check_mark: AC 18 ms 10 MB
Python 03_grid_01 :heavy_check_mark: AC 18 ms 10 MB
Python 03_grid_02 :heavy_check_mark: AC 18 ms 10 MB
Python 03_grid_03 :heavy_check_mark: AC 18 ms 10 MB
Python 03_grid_04 :heavy_check_mark: AC 18 ms 10 MB
Python 03_grid_05 :heavy_check_mark: AC 18 ms 10 MB
Python 03_grid_06 :heavy_check_mark: AC 18 ms 11 MB
Python 03_grid_07 :heavy_check_mark: AC 19 ms 11 MB
Python 03_grid_08 :heavy_check_mark: AC 19 ms 11 MB
Python 04_critical_00 :heavy_check_mark: AC 39 ms 11 MB
Python 04_critical_01 :heavy_check_mark: AC 39 ms 11 MB
Python 05_groups_00 :heavy_check_mark: AC 66 ms 11 MB
Python 05_groups_01 :heavy_check_mark: AC 67 ms 11 MB
Python 05_groups_02 :heavy_check_mark: AC 68 ms 11 MB
Python 05_groups_03 :heavy_check_mark: AC 65 ms 11 MB
Python 05_groups_04 :heavy_check_mark: AC 65 ms 11 MB
Python 06_randmax_00 :heavy_check_mark: AC 20 ms 11 MB
Python 06_randmax_01 :heavy_check_mark: AC 74 ms 11 MB
Python 06_randmax_02 :heavy_check_mark: AC 95 ms 11 MB
Python 06_randmax_03 :heavy_check_mark: AC 128 ms 11 MB
Back to top page