题意:给定一棵树的最大直径和以1为根时的最大深度,构造出一棵树满足要求.
先构造最长链,然后构造d-h这条链,然后剩下的点都连向点1.
特殊情况:d=h时其他点都连向点2; 注意d=h=1; h必须满足2h>=d.
#include <bits/stdc++.h>
using namespace std;
#define maxn 151111
int n, d, h;
int main () {
//freopen ("in.txt", "r", stdin);
while (cin >> n >> d >> h) {
if (2*h < d) {
cout << "-1\n";
}
else if (d == 1) {
if (n == 2)
cout << 1 << " " << 2 << "\n";
else cout << "-1" << "\n";
}
else if (n == 2) {
cout << 1 << " " << 2 << "\n";
}
else if (h == d) {
if (n == h+1) {
for (int i = 1; i < n; i++)
cout << i << " " << i+1 << "\n";
}
else {
for (int i = 1; i <= h; i++)
cout << i << " " << i+1 << "\n";
for (int i = h+1+1; i <= n; i++) {
cout << h << " " << i << "\n";
}
}
}
else {
for (int i = 1; i <= h; i++)
cout << i << " " << i+1 << "\n";
cout << 1 << " " << 1+h+1 << "\n";
for (int i = 1+h+1; i < 1+h+d-h; i++) {
cout << i << " " << i+1 << "\n";
}
for (int i = 1+h+d-h+1; i <= n; i++)
cout << 1 << " " << i << "\n";
}
}
return 0;
}