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;
using namespace std::chrono;
const int mxn = 1505;
int n;
int par[mxn], sz[mxn];
int cons[mxn][mxn];
bool seen_set[mxn];
vector<int> sets;
int find_set(int a) {
int temp = par[a] == a ? a : par[a] = find_set(par[a]);
return temp;
}
int join_calls = 0;
int inner_loop = 0;
void join(int a, int b) {
join_calls++;
if(sz[b] > sz[a]) swap(a, b);
par[b] = a;
sz[a] += sz[b];
for(int i : sets) if(i != a) {
cons[a][i] += cons[b][i];
cons[i][a] += cons[i][b];
inner_loop++;
}
sets.erase(find(sets.begin(), sets.end(), b));
}
void initialize(int N) {
n = N;
for(int i = 0; i < n; i++) par[i] = i, sz[i] = 1, sets.push_back(i);
}
int hasEdge(int u, int v) {
// add edge if cons between u and v are equal to sz_u * sz_v - 1
u = find_set(u), v = find_set(v);
assert(u != v);
if(cons[u][v] == sz[u]*sz[v]-1) {
join(u, v);
return 1;
}
else {
cons[u][v]++, cons[v][u]++;
}
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... |