: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.in :heavy_check_mark: AC 28 ms 10 MB
Python 00_small_01.in :heavy_check_mark: AC 23 ms 9 MB
Python 01_rand_00.in :heavy_check_mark: AC 24 ms 9 MB
Python 01_rand_01.in :heavy_check_mark: AC 22 ms 9 MB
Python 01_rand_02.in :heavy_check_mark: AC 22 ms 9 MB
Python 01_rand_03.in :heavy_check_mark: AC 22 ms 9 MB
Python 01_rand_04.in :heavy_check_mark: AC 23 ms 9 MB
Python 01_rand_05.in :heavy_check_mark: AC 22 ms 9 MB
Python 02_linear_00.in :heavy_check_mark: AC 22 ms 9 MB
Python 02_linear_01.in :heavy_check_mark: AC 24 ms 9 MB
Python 02_linear_02.in :heavy_check_mark: AC 33 ms 9 MB
Python 02_linear_03.in :heavy_check_mark: AC 45 ms 10 MB
Python 03_grid_00.in :heavy_check_mark: AC 22 ms 9 MB
Python 03_grid_01.in :heavy_check_mark: AC 22 ms 9 MB
Python 03_grid_02.in :heavy_check_mark: AC 23 ms 9 MB
Python 03_grid_03.in :heavy_check_mark: AC 24 ms 9 MB
Python 03_grid_04.in :heavy_check_mark: AC 22 ms 9 MB
Python 03_grid_05.in :heavy_check_mark: AC 22 ms 9 MB
Python 03_grid_06.in :heavy_check_mark: AC 22 ms 9 MB
Python 03_grid_07.in :heavy_check_mark: AC 23 ms 10 MB
Python 03_grid_08.in :heavy_check_mark: AC 23 ms 10 MB
Python 04_critical_00.in :heavy_check_mark: AC 45 ms 10 MB
Python 04_critical_01.in :heavy_check_mark: AC 45 ms 10 MB
Python 05_groups_00.in :heavy_check_mark: AC 80 ms 10 MB
Python 05_groups_01.in :heavy_check_mark: AC 80 ms 10 MB
Python 05_groups_02.in :heavy_check_mark: AC 77 ms 10 MB
Python 05_groups_03.in :heavy_check_mark: AC 79 ms 10 MB
Python 05_groups_04.in :heavy_check_mark: AC 78 ms 10 MB
Python 06_randmax_00.in :heavy_check_mark: AC 25 ms 10 MB
Python 06_randmax_01.in :heavy_check_mark: AC 84 ms 10 MB
Python 06_randmax_02.in :heavy_check_mark: AC 107 ms 10 MB
Python 06_randmax_03.in :heavy_check_mark: AC 145 ms 10 MB
Back to top page