algo — C++23 日本語リファレンス GitHub

test/yosupo/data_structure/unionfind.test.cpp

AC · 最終更新 2026-09-06 · GitHub

問題: https://judge.yosupo.jp/problem/unionfind

依存するヘッダ(1)
実装
// competitive-verifier: PROBLEM https://judge.yosupo.jp/problem/unionfind
#include <iostream>
#include "data_structure/union_find.hpp"

int main(void) {
    int n, q;
    std::cin >> n >> q;
    union_find uf(n);
    while (q--) {
        int t, u, v;
        std::cin >> t >> u >> v;
        if (t == 0) uf.unite(u, v);
        else std::cout << uf.same(u, v) << '\n';
    }

    return 0;
}