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 |
AC |
18 ms |
4 MB |
g++ |
max_random_00 |
AC |
17 ms |
9 MB |
g++ |
max_random_01 |
AC |
18 ms |
9 MB |
g++ |
max_random_02 |
AC |
17 ms |
9 MB |
g++ |
path_00 |
AC |
14 ms |
9 MB |
g++ |
path_01 |
AC |
14 ms |
9 MB |
g++ |
path_02 |
AC |
14 ms |
9 MB |
g++ |
path_03 |
AC |
14 ms |
9 MB |
g++ |
random_00 |
AC |
14 ms |
8 MB |
g++ |
random_01 |
AC |
14 ms |
8 MB |
g++ |
random_02 |
AC |
12 ms |
6 MB |
g++ |
random_03 |
AC |
6 ms |
4 MB |
g++ |
random_04 |
AC |
11 ms |
5 MB |
g++ |
random_05 |
AC |
13 ms |
6 MB |
g++ |
random_06 |
AC |
11 ms |
6 MB |
g++ |
random_07 |
AC |
5 ms |
4 MB |
g++ |
random_08 |
AC |
7 ms |
4 MB |
g++ |
random_09 |
AC |
17 ms |
9 MB |
Back to top page