Skip to the content.

:heavy_check_mark: test/unionfind.test.cpp

Depends on

Code

#define PROBLEM "https://judge.yosupo.jp/problem/unionfind"

#include <data_structure/unionfind.hpp>     // for unionfind
#include <fastio/base.hpp>                  // for FASTIO, cin, cout
#include <fastio/char/write.hpp>            // for operator<<
#include <fastio/signed/read.hpp>           // for operator>>
#include <fastio/signed/write.hpp>          // for operator<<
#include <templates/macro/abbrev/endl.hpp>  // for endl
#include <templates/rep.hpp>                // for rep
#include <templates/template.hpp>
#include <version>  // for std

using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    UnionFind uf(n);
    rep(_, q) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t) {
            cout << static_cast<int>(uf.same(u, v)) << endl;
        } else {
            uf.merge(u, v);
        }
    }
}
#line 1 "test/unionfind.test.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/unionfind"

#include <data_structure/unionfind.hpp>     // for unionfind
#include <fastio/base.hpp>                  // for FASTIO, cin, cout
#include <fastio/char/write.hpp>            // for operator<<
#include <fastio/signed/read.hpp>           // for operator>>
#include <fastio/signed/write.hpp>          // for operator<<
#include <templates/macro/abbrev/endl.hpp>  // for endl
#include <templates/rep.hpp>                // for rep
#include <templates/template.hpp>
#include <version>  // for std

using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    UnionFind uf(n);
    rep(_, q) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t) {
            cout << static_cast<int>(uf.same(u, v)) << endl;
        } else {
            uf.merge(u, v);
        }
    }
}

Test cases

Env Name Status Elapsed Memory
g++ example_00 :heavy_check_mark: AC 18 ms 4 MB
g++ max_random_00 :heavy_check_mark: AC 17 ms 9 MB
g++ max_random_01 :heavy_check_mark: AC 18 ms 9 MB
g++ max_random_02 :heavy_check_mark: AC 17 ms 9 MB
g++ path_00 :heavy_check_mark: AC 14 ms 9 MB
g++ path_01 :heavy_check_mark: AC 14 ms 9 MB
g++ path_02 :heavy_check_mark: AC 14 ms 9 MB
g++ path_03 :heavy_check_mark: AC 14 ms 9 MB
g++ random_00 :heavy_check_mark: AC 14 ms 8 MB
g++ random_01 :heavy_check_mark: AC 14 ms 8 MB
g++ random_02 :heavy_check_mark: AC 12 ms 6 MB
g++ random_03 :heavy_check_mark: AC 6 ms 4 MB
g++ random_04 :heavy_check_mark: AC 11 ms 5 MB
g++ random_05 :heavy_check_mark: AC 13 ms 6 MB
g++ random_06 :heavy_check_mark: AC 11 ms 6 MB
g++ random_07 :heavy_check_mark: AC 5 ms 4 MB
g++ random_08 :heavy_check_mark: AC 7 ms 4 MB
g++ random_09 :heavy_check_mark: AC 17 ms 9 MB
Back to top page