This documentation is automatically generated by competitive-verifier/competitive-verifier
// competitive-verifier: PROBLEM https://judge.yosupo.jp/problem/unionfind
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
using namespace std;
#include "../../src/ds/dsu_short.hpp"
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, q;
cin >> n >> q;
DSU dsu(n);
while (q--) {
int op, u, v;
cin >> op >> u >> v;
if (op == 0) {
dsu.fa[dsu.find(u)] = dsu.find(v);
} else {
cout << (dsu.find(u) == dsu.find(v)) << "\n";
}
}
return 0;
}
#line 1 "test/ds/dsu_short.test.cpp"
// competitive-verifier: PROBLEM https://judge.yosupo.jp/problem/unionfind
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
using namespace std;
#line 1 "src/ds/dsu_short.hpp"
struct DSU {
vector<int> fa;
DSU(int n) : fa(n) { iota(ALL(fa), 0); }
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
};
#line 7 "test/ds/dsu_short.test.cpp"
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, q;
cin >> n >> q;
DSU dsu(n);
while (q--) {
int op, u, v;
cin >> op >> u >> v;
if (op == 0) {
dsu.fa[dsu.find(u)] = dsu.find(v);
} else {
cout << (dsu.find(u) == dsu.find(v)) << "\n";
}
}
return 0;
}
| Env | Name | Status | Elapsed | Memory |
|---|---|---|---|---|
| g++ | example_00 |
|
5 ms | 4 MB |
| g++ | max_random_00 |
|
44 ms | 4 MB |
| g++ | max_random_01 |
|
44 ms | 4 MB |
| g++ | max_random_02 |
|
43 ms | 4 MB |
| g++ | path_00 |
|
36 ms | 4 MB |
| g++ | path_01 |
|
39 ms | 6 MB |
| g++ | path_02 |
|
36 ms | 4 MB |
| g++ | path_03 |
|
38 ms | 6 MB |
| g++ | random_00 |
|
33 ms | 4 MB |
| g++ | random_01 |
|
33 ms | 4 MB |
| g++ | random_02 |
|
27 ms | 4 MB |
| g++ | random_03 |
|
9 ms | 4 MB |
| g++ | random_04 |
|
23 ms | 4 MB |
| g++ | random_05 |
|
31 ms | 4 MB |
| g++ | random_06 |
|
25 ms | 4 MB |
| g++ | random_07 |
|
7 ms | 4 MB |
| g++ | random_08 |
|
12 ms | 4 MB |
| g++ | random_09 |
|
42 ms | 4 MB |