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 asked[1501][1501];
vector<int> e;
int n;
int find(int u){
return e[u] < 0 ? u : e[u] = find(e[u]);
}
int sz(int u){
return -e[find(u)];
}
void unite(int u, int v){
u = find(u), v = find(v);
if(u==v) return;
if(e[u] > e[v]) swap(u, v);
for(int i=1; i<=n; ++i){
asked[u][i] += asked[v][i];
asked[i][u] += asked[i][v];
}
e[u] += e[v], e[v] = u;
}
void initialize(int N){
n = N;
e.assign(n+1, -1);
for(int i=0; i<=n; ++i)
for(int j=0; j<=n; ++j)
asked[i][j] = 0;
}
int hasEdge(int u, int v){
++u, ++v;
u = find(u), v = find(v);
if(u==v) return 1;
++asked[u][v];
++asked[v][u];
if(asked[u][v]==sz(u)*sz(v)){
unite(u, v);
return 1;
}
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... |