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;
const int MAXN=1505;
#define ll long long
#define fi first
#define se second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mid (l+r)/2
#define sz(a) int((a).size())
#define all(a) a.begin(),b.begin()
#define mod 1000000007LL
#define endl "\n"
#define PRINT(x) cout<<#x<<'-'<<x<<endl
int dsu[MAXN],sz[MAXN];
vector<vector<int>> cnt(MAXN,vector<int>(MAXN,1));
int root(int x){
while(x!=dsu[x]){
dsu[x]=dsu[dsu[x]];
x=dsu[x];
}
return x;
}
void connect(int x,int y){
x=root(x); y=root(y);
if(x!=y){
if(sz[x]<sz[y]){
swap(x,y);
}
dsu[y]=x;
sz[x]+=sz[y];
}
}
void initialize(int n){
iota(dsu,dsu+MAXN,0);
fill(sz,sz+MAXN,1);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i!=j){
cnt[i][j]=1;
cnt[j][i]=1;
}
else{
cnt[i][j]=0;
}
}
}
}
int hasEdge(int u, int v){
int rtu=root(u),rtv=root(v);
if(cnt[rtu][rtv]==1){
cnt[rtu][rtv]=0;
cnt[rtv][rtu]=0;
connect(u,v);
set<int> visited;
for(int k=0;k<MAXN;k++){
int rtk=root(k);
if(visited.find(rtk)!=visited.end()) continue;
if(rtk==rtu || rtk==rtv) continue;
cnt[rtu][rtk]+=cnt[rtv][rtk];
cnt[rtk][rtu]=cnt[rtu][rtk];
cnt[rtv][rtk]=cnt[rtu][rtk];
cnt[rtk][rtv]=cnt[rtu][rtk];
visited.insert(rtk);
}
return 1;
}
else{
int rtu=root(u),rtv=root(v);
cnt[rtu][rtv]--;
cnt[rtv][rtu]--;
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... |