#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 |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Wrong Answer[1] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Wrong Answer[1] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Wrong Answer[1] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Wrong Answer[1] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Wrong Answer[1] |
3 |
Halted |
0 ms |
0 KB |
- |