#include "icc.h"
#include <iostream>
#include <set>
#include <vector>
using namespace std;
#define vll vector<int>
const int N=200;
int par[N];
int sz[N];
// bool adj[N][N];
// int query(int n,int m,int a[],int b[])
// {
// for(int i=0;i<n;i++)
// {
// for(int j=0;j<m;j++)
// {
// if(adj[a[i]][b[j]])
// return 1;
// }
// }
// return 0;
// }
void init(int n)
{
for(int i=1;i<=n;i++)
{
par[i]=i;
sz[i]=1;
}
}
int root(int x)
{
return (par[x]==x?x:par[x]=root(par[x]));
}
void join(int x,int y)
{
x=root(x);
y=root(y);
if(x!=y)
{
par[x]=y;
sz[y]+=sz[x];
}
}
int n_n_n;
vll modify(vll& a)
{
vll b;
for(auto i:a)
for(int j=1;j<=n_n_n;j++)
if(root(j)==i)
b.push_back(j);
return b;
}
int check_edge(vll& a,vll& b)
{
int n=a.size();
int m=b.size();
int a_[n];
for(int i=0;i<n;i++)
a_[i]=a[i];
int b_[m];
for(int i=0;i<m;i++)
b_[i]=b[i];
return query(n,m,a_,b_);
}
int check_edge1(vll& c,vll& d)
{
vll a=modify(c),b=modify(d);
int n=a.size();
int m=b.size();
int a_[n];
for(int i=0;i<n;i++)
a_[i]=a[i];
int b_[m];
for(int i=0;i<m;i++)
b_[i]=b[i];
return query(n,m,a_,b_);
}
vll fit,sed;
int fix_first(int l,int r)
{
if(l==r)
return l;
int mid=(l+r)/2;
vll cur;
for(int i=l;i<=mid;i++)
cur.push_back(fit[i]);
if(check_edge(cur,sed))
return fix_first(l,mid);
else
return fix_first(mid+1,r);
}
void between(vll& a,vll& b)
{
a=modify(a);
b=modify(b);
fit=a;
sed=b;
int ind=fix_first(0,((int)a.size())-1);
fit={fit[ind]};
swap(sed,fit);
ind=fix_first(0,((int)b.size())-1);
fit={fit[ind]};
}
void run(int n)
{
n_n_n=n;
init(n);
int q=n-1;
set<int> sp;
sp.insert(0);
for(int i=1;i<=n;i++)
sp.insert(i);
while(q--)
{
// cout<<"New edge\n";
// int x_,y_;
// cin>>x_>>y_;
// adj[x_][y_]=adj[y_][x_]=1;
vll shif(sp.begin(), sp.end());
int s=1;
int e=shif.size();
while(s+1<e)
{
int mid=(s+e)/2;
vll big;
for(int i=1;i<mid;i++)
big.push_back(shif[i]);
vll pk={shif[mid]};
if(check_edge1(big,pk)){
e=mid;
}
else
{
s=mid;
}
}
vll pk={shif[e]};
vll big;
for(int j=1;j<e;j++)
big.push_back(shif[j]);
between(big,pk);
join(fit[0],sed[0]);
if(par[fit[0]]==fit[0])
{
sp.erase(sed[0]);
}
else
{
sp.erase(fit[0]);
}
// cout<<"Edge is "<<fit[0]<<' '<<sed[0]<<endl;
setRoad(fit[0],sed[0]);
// break;
}
}
// int main()
// {
// int n;
// cin>>n;
// run(n);
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
856 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
860 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |