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"
#define shit cout << "shit\n";
using namespace std;
struct subset{
int parent;
int rank;
};
subset subsets[1510];
int n;
vector<vector<int>> setList(1501,vector<int>());
int find(int x){
if(subsets[x].parent==x)return x;
subsets[x].parent = find(subsets[x].parent);
return subsets[x].parent;
}
void Union(int X,int Y){
int x = find(X);
int y = find(Y);
if(subsets[x].rank<subsets[y].rank){
subsets[x].parent = y;
setList.at(y).push_back(X);
}else if(subsets[x].rank>subsets[y].rank){
subsets[y].parent = x;
setList.at(x).push_back(Y);
}else{
subsets[x].parent = y;
subsets[y].rank++;
setList.at(y).push_back(X);
}
}
bool flag[1501][1501];
void initialize(int N) {
n=N;
for(int i=0;i<n;i++){
subsets[i] = {i,1};
setList.at(i).push_back(i);
}
}
bool getRemaining(int u,int v){
vector<int> u_set,v_set;
int U =find(u),V = find(v);
// for(int i=0;i<n;i++){
// // int p = find(i);
// int p = subsets[i].parent;
// if(p==U)u_set.push_back(i);
// if(p==V)v_set.push_back(i);
// }
int C = 0;
// for(int a:setList.at(U))
// cout << a << "\t";
// cout << endl;
// for(int b:setList.at(V))
// cout << b << "\t";
// cout << endl;
for(int a:setList.at(U)){
for(int b:setList.at(V)){
if(!flag[a][b])C++;
if(C>=2)return false;
}
}
return true;
}
int hasEdge(int u, int v) {
int r = 0;
if(getRemaining(u,v))r=1;
flag[u][v] =flag[v][u] = true;
if(r==1)
Union(u,v);
return r;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |