[题目链接]

https://codeforces.com/problemset/problem/639/B

[算法]

当d > n - 1或h > n - 1时 , 无解

当2h < d时无解

当d = 1 , n不为2时 , 无解

否则 , 我们先构造一条长度为h的链 , 然后 , 将一条(d - h)的链接到根上 , 再将剩余节点接到根上

时间复杂度 : O(N)

[代码]

#include<bits/stdc++.h>
using namespace std; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
} int main()
{ int n , h , d;
read(n); read(d); read(h);
if (d > n - || h > n - )
{
printf("-1\n");
return ;
}
if (h * < d)
{
printf("-1\n");
return ;
}
if (d == && n != )
{
printf("-1\n");
return ;
}
for (int i = ; i <= h + ; i++) printf("%d %d\n",i,i - );
for (int i = ; i <= d - h; i++)
{
if (i == ) printf("%d %d\n",,h + + i);
else printf("%d %d\n",h + i,h + + i);
}
if (d == h)
{
for (int i = d + ; i <= n; i++)
printf("%d %d\n",,i);
} else
{
for (int i = d + ; i <= n; i++)
printf("%d %d\n",,i);
} return ; }

[Codeforces 639B] Bear and Forgotten Tree 3的更多相关文章

  1. Codeforces 639B——Bear and Forgotten Tree 3——————【构造、树】

    Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  2. Codeforces 658C Bear and Forgotten Tree 3【构造】

    题目链接: http://codeforces.com/contest/658/problem/C 题意: 给定结点数,树的直径(两点的最长距离),树的高度(1号结点距离其他结点的最长距离),写出树边 ...

  3. CodeForces 658C Bear and Forgotten Tree 3 (构造)

    题意:构造出一个 n 个结点,直径为 m,高度为 h 的树. 析:先构造高度,然后再构造直径,都全了,多余的边放到叶子上,注意直径为1的情况. 代码如下: #pragma comment(linker ...

  4. Code Forces Bear and Forgotten Tree 3 639B

    B. Bear and Forgotten Tree 3 time limit per test2 seconds memory limit per test256 megabytes inputst ...

  5. codeforces 658C C. Bear and Forgotten Tree 3(tree+乱搞)

    题目链接: C. Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes ...

  6. VK Cup 2016 - Round 1 (Div. 2 Edition) C. Bear and Forgotten Tree 3 构造

    C. Bear and Forgotten Tree 3 题目连接: http://www.codeforces.com/contest/658/problem/C Description A tre ...

  7. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) E. Bear and Forgotten Tree 2 bfs set 反图的生成树

    E. Bear and Forgotten Tree 2 题目连接: http://www.codeforces.com/contest/653/problem/E Description A tre ...

  8. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) E - Bear and Forgotten Tree 2 链表

    E - Bear and Forgotten Tree 2 思路:先不考虑1这个点,求有多少个连通块,每个连通块里有多少个点能和1连,这样就能确定1的度数的上下界. 求连通块用链表维护. #inclu ...

  9. VK Cup 2016 - Round 1 (Div. 2 Edition) C. Bear and Forgotten Tree 3

    C. Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes input ...

随机推荐

  1. 理解ZAB协议

    ZAB协议 介绍 1.zab协议是为分布式协调服务zookpeer专门设计的一种支持崩溃恢复的原子广播协议 2.在zookeeper中主要依赖ZAB协议来实现数据一致性,基于该协议zk实现了一种主备模 ...

  2. LeetCode(64) Minimum Path Sum

    题目 Total Accepted: 47928 Total Submissions: 148011 Difficulty: Medium Given a m x n grid filled with ...

  3. poj2325 大数除法+贪心

    将输入的大数除以9 无法整除再除以 8,7,6,..2,如果可以整除就将除数记录,将商作为除数继续除9,8,...,3,2. 最后如果商为1 证明可以除尽 将被除过的数从小到大输出即可 #includ ...

  4. 九度教程第22题——今年暑假不AC(看尽量多的电视节目)

    #define _CRT_SECURE_NO_DEPRECATE #include <stdio.h> #include <algorithm> using namespace ...

  5. linux shell & man chmod

    man chomd MBP xgqfrms-mbp:~ xgqfrms-mbp$ man chmod and entries will be removed regardless of their i ...

  6. 概率dp呜呜

    概率dp有环怎么办? 答案可劲迭代 ,然后可劲消元 , 怎么消? 我就不知道了. 呵呵

  7. 2014ACM/ICPC亚洲区西安站现场赛 F color(二项式反演)

    题意:小球排成一排,从m种颜色中选取k种颜色给n个球上色,要求相邻的球的颜色不同,求可行的方案数,答案模1e9+7.T组数据,1<= n, m <= 1e9, 1 <= k < ...

  8. mysql-performance-schema

    http://www.fromdual.com/mysql-performance-schema-hints http://www.cnblogs.com/cchust/

  9. sdfs

    <!DOCTYPE html><html><head><meta charset="GB18030"><title>In ...

  10. 异 形 卵 709 南阳oj

    http://acm.nyist.net/JudgeOnline/problem.php? pid=709 异 形 卵 时间限制:1000 ms  |  内存限制:65535 KB 难度: 描写叙述 ...