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
set< pair<int,int> > edge_set[N];
int ata[N],n;
int bul(int node) {
if(ata[node]==node) return node;
return ata[node]=bul(ata[node]);
}
bool ok[N][N];
int cnt=0;
void initialize(int n) {
::n=n;
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) ok[i][j]=1;
}
}
bool vis[N];
void dfs(int node) {
if(vis[node]) return ;
vis[node]=1;
for(int i=0;i<n;i++) {
if(ok[node][i]) dfs(i);
}
}
int hasEdge(int u, int v) {
memset(vis,0,sizeof(vis));
ok[u][v]=ok[v][u]=0;
dfs(u);
if(vis[v]) return 0;
return ok[u][v]=ok[v][u]=1;
}
/*
#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) {
flag=1;
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... |