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>
#define st first
#define nd second
#define mp make_pair
#define sz(x) x.size()
using namespace std;
#define N 1505
int ata[N],n,tot[N][N];
vector<int> grs;
int bul(int node) {
if(ata[node]==node) return node;
return ata[node]=bul(ata[node]);
}
void initialize(int n) {
::n=n;
for(int i=0;i<n;i++) {
ata[i]=i;
grs.push_back(i);
for(int j=0;j<n;j++) {
if(i==j) continue ;
tot[i][j]=1;
}
}
}
int hasEdge(int u, int v) {
int pu=bul(u);
int pv=bul(v);
tot[pu][pv]--;
tot[pv][pu]--;
if(!tot[pu][pv]) {
for(auto gr:grs) {
if(gr==pu) {
continue ;
}
tot[gr][pv]+=tot[gr][pu];
tot[pv][gr]+=tot[pu][gr];
tot[gr][pu]=tot[pu][gr]=0;
}
ata[pu]=pv;
grs.erase(find(grs.begin(),grs.end(),pu));
return 1;
}
return 0;
}
/*
#include <cstdio>
#include <cassert>
#include "game.h"
int read_int() {
int x;
assert(scanf("%d", &x) == 1);
return x;
}
int bab[N];
int fin(int node) {
if(bab[node]==node) return node;
return bab[node]=fin(bab[node]);
}
void bug(vector< pair<int,int> > ed,int n) {
initialize(n);
for(auto x:ed) {
printf("%d %d\n",x.st,x.nd);
printf("%d\n",hasEdge(x.st,x.nd));
}
}
int main() {
int n, u, v;
n = 5;
vector< pair<int,int> > ed;
for(int i=0;i<n;i++) {
for(int j=0;j<i;j++) {
ed.push_back(mp(i,j));
}
}
int tot=0;
do {
int comp=n;
for(int i=0;i<n;i++) bab[i]=i;
initialize(n);
for (int i = 0; i < n * (n - 1) / 2; i++) {
u = ed[i].st;
v = ed[i].nd;
// printf("%d %d ",u,v);
int res=hasEdge(u,v);
if(res) {
int bu=fin(u);
int bv=fin(v);
if(bu!=bv) {
bab[bu]=bv;
comp--;
}
}
if(comp==1 && i<n*(n-1)/2-1) {
bug(ed,n);
return 0;
}
}
if(comp>1) {
bug(ed,n);
return 0;
}
} while(next_permutation(ed.begin(),ed.end()));
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... |