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;
typedef long long ll;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ed <<endl;
vector<vector<int>> s(1500, vector<int>(1500, 1));
struct unionFind{
vector<int> par;
vector<int> rnk;
void init(int n){
par.resize(n);
rnk.resize(n);
for(int i=0;i<n;i++){
par[i] =i;
rnk[i]=0;
}
};
int find(int p){
// cerr << imie(p) << endl;
if(par[p] != p){
return find(par[p]);
}
//path compression might fuck it up;
return p;
}
void join(int u, int v){
int ur = find(u);
int vr = find(v);
if(ur == vr){
return;
}
if(rnk[vr] > rnk[ur]) swap(ur, vr);
if(rnk[ur] == rnk[vr]) rnk[ur]++;
par[vr] = ur;
vector<int> proc(1500);
for(int i=0;i<1500;i++){
// debug() << imie(i);
// cerr << imie(i) << endl;
int r = find(i);
if(proc[r] == 0 && r != ur){
int mn = min(ur, r);
int mx = max(ur, r);
int mn2= min(vr, r);
int mx2= max(vr, r);
s[mn][mx] += s[mn2][mx2];
proc[r] = 1;
}
}
}
};
unionFind uf;
void initialize(int n) {
uf.init(1501);
}
int hasEdge(int u, int v) {
u = uf.find(u);
v = uf.find(v);
if(u==v){
return 1;
}
if(u > v) swap(u, v);
// cerr << imie(u) imie(v) imie(s[u][v]) << endl;
if(s[u][v] == 1){
uf.join(u, v);
return 1;
} else{
s[u][v]--;
return 0;
}
// return 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |