This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
class dsu {
public:
vector<int> par, sz;
void build(int n) {
par.resize(n);
sz.resize(n);
iota(par.begin(), par.end(), 0);
}
int find(int v) {
return (par[v] == v) ? v : par[v] = find(par[v]);
}
bool unite(int u, int v) {
u = find(u);
v = find(v);
if (u == v) {
return false;
}
if (sz[u] < sz[v]) {
swap(u, v);
}
sz[u] += sz[v];
par[v] = u;
return true;
}
bool same(int u, int v) {
return (find(u) == find(v));
}
};
dsu ds;
int _k;
void init(int n, int k) {
ds.build(n);
_k = k;
}
int add_teleporter(int u, int v) {
for (int i = 0; i < _k; i++) {
if (ds.same(i, u) && ds.same(i, v)) {
return true;
}
}
ds.unite(u, v);
return false;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |