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 <bits/stdc++.h>
#include "game.h"
using namespace std;
int parent[1501];
int countt[1501][1501];
int sizee[1501];
int N;
int root(int x) {
if (parent[x]==x) return x;
return parent[x] = root(parent[x]);
}
bool isConnected(int x, int y) {
return root(x) == root(y);
}
void connect(int x, int y) {
int rootX = root(x);
int rootY = root(y);
if(rootX != rootY){
parent[rootX] = rootY;
sizee[rootY] += sizee[rootX];
for (int i=0;i<N;i++){
if (root(i)==i && i!=rootY){
countt[rootY][i]+=countt[rootX][i];
countt[i][rootY]+=countt[i][rootX];
}
}
}
}
void initialize(int n){
for (int i=0;i<n;i++) {
parent[i]=i;
sizee[i]=1;
}
N=n;
}
int hasEdge(int u, int v){
int rootu=root(u),rootv=root(v);
if (countt[rootu][rootv]==sizee[rootu]*sizee[rootv]-1){
connect(u,v);
return 1;
}
countt[rootu][rootv]++;
countt[rootv][rootu]++;
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... |