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;
int co[1500][1500];
struct UF {
vector<vector<int>> vs;
vector<int> par;
int n;
void build(int n_) {
n = n_;
vs.resize(n);
par.resize(n);
for (int i = 0; i < n; i++) {
vs[i].push_back(i);
par[i] = i;
}
}
bool unite(int u, int v) {
if (par[u] == par[v]) {
return false;
}
int tu = u, tv = v;
u = par[tu];
v = par[tv];
int su = vs[u].size(), sv = vs[v].size();
if (su < sv) {
swap(u, v);
swap(su, sv);
swap(tu, tv);
}
co[u][v]++;
co[v][u]++;
if (co[u][v] == su * sv) {
for (auto &e : vs[v]) {
vs[u].push_back(e);
par[e] = u;
}
for (int i = 0; i < n; i++) {
co[u][i] += co[v][i];
co[i][u] += co[i][v];
}
return true;
}
return false;
}
};
UF uf;
void initialize(int n) { uf.build(n); }
int hasEdge(int u, int v) {
if (uf.unite(u, v)) {
return 1;
} else {
return 0;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |