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;
#define pb push_back
#define fr first
#define sc second
const int maxn = 1510;
int n, ds[maxn], dsz[maxn];
int ask[maxn][maxn];
int find(int v) {
if(v == ds[v]) return v;
return ds[v] = find(ds[v]);
}
void join(int u, int v) {
if(dsz[u] < dsz[v]) swap(u,v);
dsz[u]+= dsz[v];
for(int x = 0; x < n; x++) {
ask[u][x]+= ask[v][x];
ask[x][u]+= ask[x][v];
}
ds[v] = u;
}
void initialize(int N) {
n = N;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(i != j) {
ask[i][j] = 1;
ask[j][i] = 1;
}
}
}
for(int i = 0; i < n; i++) {
ds[i] = i;
dsz[i] = 1;
}
}
int hasEdge(int u, int v) {
u = find(u);
v = find(v);
ask[u][v]--;
ask[v][u]--;
if(find(u) == find(v)) return 0;
// assert(u != v);
if(ask[u][v] == 0) {
join(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... |