题解:CF639B Bear and Forgotten Tree 3
分讨构造题。
首先肯定判掉无解。无解情况有
接着就是考虑构造方式了。
首先我们肯定需要一条从根节点出发长度为
剩下的点我们需要找一个节点挂上去。容易想到若
显然
照着以上思路做一遍即可,没什么细节。
#include<bits/stdc++.h>
using namespace std;
long long n,h,d;
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>d>>h;
if(h*2<d)
{
cout<<-1;
return 0;
}
if(d==1)
{
if(n==2)
cout<<"1 2";
else
cout<<-1;
return 0;
}
for(int i=2;i<=h+1;i++)
cout<<i-1<<' '<<i<<'\n';
if(h!=d)
{
cout<<"1 "<<h+2<<'\n';
for(int i=h+3;i<=d+1;i++)
cout<<i-1<<' '<<i<<'\n';
for(int i=d+2;i<=n;i++)
cout<<"1 "<<i<<'\n';
}
else
{
for(int i=h+2;i<=n;i++)
cout<<"2 "<<i<<'\n';
}
return 0;
}