이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "game.h"
#include<bits/stdc++.h>
using namespace std;
///Disjoint Sets
///Create a tree in exactly n(n-1)/2 movements
int n;
int link[1505];
int setSize[1505];
int root(int u)
{
if(link[u]==u) return u;
else return link[u]=root(link[u]);
}
void join(int a,int b)
{
a=root(a);
b=root(b);
if(a==b) return;
if(setSize[a]<setSize[b]) swap(a,b);
link[b]=a;
setSize[a]+=setSize[b];
}
int maybe[1505][1505]; //Maybe[i][j] is the number of edges between nodes i,j that are not asked yet
void initialize(int N) {
n=N;
for(int i=0;i<n;i++){
link[i]=i;
setSize[i]=1;
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j) continue;
maybe[i][j]=1; //There is a possible edge from each note to other
}
}
}
int hasEdge(int u, int v) {
u=root(u);
v=root(v);
if(maybe[u][v]==1){ //The last edge between those components, so we use it
if(setSize[v]>setSize[u]) swap(u,v);
for(int i=0;i<n;i++){
maybe[i][u]+=maybe[i][v]; //We add the edges of component v to component u
maybe[u][i]+=maybe[v][i];
}
join(u,v);
return 1;
}
else{ //Too many edges, we discard it
maybe[u][v]--;
maybe[v][u]--;
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... |