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;
const int N = 1500;
int n;
vector<int> p(N);
vector<vector<int>> comp(N), ways(N, vector(N, 0));
void initialize(int _n) {
n = _n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i != j) ways[i][j]++;
}
p[i] = i;
comp[i].emplace_back(i);
}
}
void merge(int u, int v) {
u = p[u], v = p[v];
assert(u != v);
if (comp[u].size() < comp[v].size()) swap(u, v);
for (int x: comp[v]) {
p[x] = u;
comp[u].emplace_back(x);
}
comp[v].clear();
for (int i = 0; i < n; i++) {
ways[u][i] += ways[v][i];
ways[i][u] += ways[v][i];
}
}
int hasEdge(int u, int v) {
if (p[u] == p[v]) return 0;
if (ways[p[u]][p[v]] > 1) {
ways[p[u]][p[v]]--;
ways[p[v]][p[u]]--;
return 0;
}
merge(u, v);
return 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |