이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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],rem[N],n;
int bul(int node) {
if(ata[node]==node) return node;
return ata[node]=bul(ata[node]);
}
int ok[N][N];
int cnt=0;
void initialize(int n) {
::n=n;
for(int i=0;i<n;i++) {
edge_set[i].clear();
for(int j=0;j<n;j++) {
if(j==i) continue ;
edge_set[i].insert({min(i,j),max(i,j)});
}
cnt=0;
ata[i]=i;
}
for(int i=0;i<n;i++) for(int j=0;j<n;j++) ok[i][j]=0;
}
void finish(int au) {
int node1=edge_set[au].begin()->st;
int node2=edge_set[au].begin()->nd;
ok[node1][node2]=ok[node2][node1]=1;
cnt++;
edge_set[bul(node1)].erase(edge_set[bul(node1)].find({min(node1,node2),max(node1,node2)}));
edge_set[bul(node2)].erase(edge_set[bul(node2)].find({min(node1,node2),max(node1,node2)}));
int anode1=bul(node1);
int anode2=bul(node2);
if(sz(edge_set[anode1])<sz(edge_set[anode2])) {
swap(anode1,anode2);
}
ata[anode2]=anode1;
if(sz(edge_set[bul(anode1)])==1) {
finish(bul(anode1));
}
if(sz(edge_set[bul(anode2)])==1) {
finish(bul(anode2));
}
}
int tot=0;
bool flag=false;
int hasEdge(int u, int v) {
int au=bul(u);
int av=bul(v);
if(ok[u][v]) {
return 1;
}
edge_set[au].erase(edge_set[au].find({min(u,v),max(u,v)}));
edge_set[av].erase(edge_set[av].find({min(u,v),max(u,v)}));
if(sz(edge_set[bul(au)])==1) {
finish(bul(au));
}
if(sz(edge_set[bul(av)])==1) {
finish(bul(av));
}
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) {
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... |