#include <bits/stdc++.h>
#include "icc.h"
using namespace std;
int n;
vector<int> dsu[105];
int comp[105],a[105],b[105],asize,bsize;
int comps[105][105];
void dsu_merge(int c1,int c2)
{
if(dsu[c1].size()<dsu[c2].size())
swap(c1,c2);
for(int i:dsu[c2])
{
comp[i]=c1;
dsu[c1].push_back(i);
}
dsu[c2].clear();
}
int adj[105][105];
/*int query(int asize,int bsize, int v[105],int w[105])
{
for(int i=0;i<asize;i++)
for(int j=0;j<bsize;j++)
if(adj[v[i]][w[j]])
return 1;
return 0;
}
void setRoad(int x,int y)
{
cout<<x<<' '<<y<<'\n';
adj[x][y]=adj[y][x]=1;
}*/
void run(int N)
{
n=N;
for(int i=1;i<=n;i++)
{
dsu[i].push_back(i);
comp[i]=i;
}
int nr=n;
for(int z=1;z<n;z++,nr--)
{
int cnt=0;
/*int h,e;
cin>>h>>e;
adj[h][e]=adj[e][h]=1;*/
for(int i=1;i<=n;i++)
if(dsu[i].size())
{
cnt++;
for(int j:dsu[i])
comp[j]=cnt;
dsu[cnt]=dsu[i];
if(i!=cnt)
dsu[i].clear();
}
int rad=sqrt(nr);
int rest=nr%rad;
int lg=0;
for(int i=1;i<=nr;)
{
int l=rad;
if(rest)
{
rest--;
l++;
}
int j;
lg++;
int poz=0;
for(j=i;j<=i+l-1;j++)
{
for(int q:dsu[j])
comps[lg][++poz]=q;
}
i=j;
}
int buck1=0,buck2=0;
for(int i=1;i<=lg;i++)
{
int asize=0,bsize=0;
for(int j=1;j<=n&&comps[i][j]!=0;j++)
a[asize++]=comps[i][j];
for(int j=1;j<=lg;j++)
if(j!=i)
{
for(int k=1;k<=n&&comps[j][k]!=0;k++)
b[bsize++]=comps[j][k];
}
int ans=query(asize,bsize,a,b);
if(ans==1)
{
if(buck1==0)
buck1=i;
else
{
buck2=i;
break;
}
}
}
int L=0;
for(int i=1;i<=n&&comps[buck1][i]!=0;i++,L++);
int st=1;
int dr=L;
int x=0;
while(st<=dr)
{
int mij=(st+dr)/2;
int asize=0;
for(int i=1;i<=mij;i++)
a[asize++]=comps[buck1][i];
int bsize=0;
for(int i=1;i<=n&&comps[buck2][i]!=0;i++)
b[bsize++]=comps[buck2][i];
int ans=query(asize,bsize,a,b);
if(ans==1)
{
x=comps[buck1][mij];
dr=mij-1;
}
else
st=mij+1;
}
L=0;
for(int i=1;i<=n&&comps[buck2][i]!=0;i++,L++);
st=1;
dr=L;
int y=0;
while(st<=dr)
{
int mij=(st+dr)/2;
int asize=0;
for(int i=1;i<=mij;i++)
a[asize++]=comps[buck2][i];
int bsize=0;
for(int i=1;i<=n&&comps[buck1][i]!=0;i++)
b[bsize++]=comps[buck1][i];
int ans=query(asize,bsize,a,b);
if(ans==1)
{
y=comps[buck2][mij];
dr=mij-1;
}
else
st=mij+1;
}
dsu_merge(comp[x],comp[y]);
setRoad(x,y);
}
}
/*int main()
{
int N;
cin>>N;
run(N);
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
496 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
Wrong road! |
2 |
Halted |
0 ms |
0 KB |
- |