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 <iostream>
#include <vector>
#include "game.h"
using namespace std;
vector<int> group;
vector<vector<int>> cons;
int gn;
int get(int u){
int s = u;
while(u != group[u]) u = group[u];
while(s != group[s]){
int ls = s;
s = group[s];
group[ls] = u;
}
return u;
}
void unite(int u, int v){
u = get(u); v = get(v);
for(int adder = 0; adder < gn; ++adder) cons[u][adder] += cons[v][adder];
for(int oc = 0; oc < gn; ++oc) cons[oc][u] += cons[oc][v];
group[v] = u;
}
void initialize(int n){
group.resize(n); for(int i = 0; i < n; ++i) group[i] = i;
cons.assign(n, vector<int> (n, 1)); for(int i = 0; i < n; ++i) cons[i][i] = 0;
gn = n;
}
int hasEdge(int u, int v){
if(cons[get(u)][get(v)] != 1){
cons[get(u)][get(v)] -= 1;
cons[get(v)][get(u)] -= 1;
return 0;
}
else{
unite(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... |