题解:CF639B Bear and Forgotten Tree 3
一道简单构造题。 先构造出两条链(如图)。
1
/ \
2 h + 2
/ \
. .
. .
. .
/ \
h d
/ \
h + 1 d + 1
此时还剩下一些点,
这时分类讨论,
然后
code:
#include <bits/stdc++.h>
using namespace std;
int n, d, h;
int main() {
cin >> n >> d >> h;
if (d > 2 * h || (d == 1 && h == 1 && n > 2)) { // 特判
cout << "-1\n";
return 0;
}
for (int i = 2; i <= h + 1; i ++) cout << i - 1 << " " << i << "\n";
for (int i = h + 2; i <= d + 1; i ++) cout << (i == h + 2 ? 1 : i - 1) << " " << i << "\n";
for (int i = d + 2; i <= n; i ++) cout << (d == h ? 2 : 1) << " " << i << "\n";
return 0;
}