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 <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <assert.h>
#include <memory.h>
using namespace std;
typedef pair<int,int> pii;
int dsu[2010],p[2010],N,cnt,number;
bool E[2010][2010];
int find(int u,int *dsu){
return dsu[u] == u ? u : dsu[u] = find(dsu[u],dsu);
}
void initialize(int n) {
N = n;
number = n;
for (int i = 0; i < n; ++i){
dsu[i] = i;
}
}
int hasEdge(int u, int v) {
E[u][v] = E[v][u] = 1;
cnt++;
int a = find(u,dsu);
int b = find(v,dsu);
if(a == b){
return 0;
}
int res = 0,cmp = 0;
for(int i = 0 ; i < N ; i++){
p[i] = dsu[i];
}
for(int i = 0 ; i < N ; i++)
for(int j = i + 1 ; j < N ; j++){
if(!E[i][j]){
int a = find(i,p);
int b = find(j,p);
p[a] = b;
}
}
int cnt = 0;
for(int i = 0 ; i < N ; i++){
if(find(i,p) == i)
cnt++;
}
if(cnt != 1){
dsu[a] = b;
return 1;
}
return 0;
}
Compilation message (stderr)
game.cpp: In function 'int hasEdge(int, int)':
game.cpp:37:6: warning: unused variable 'res' [-Wunused-variable]
int res = 0,cmp = 0;
^
game.cpp:37:14: warning: unused variable 'cmp' [-Wunused-variable]
int res = 0,cmp = 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... |