CF1041E Tree Reconstruction 构造题

题意翻译

题目大意:

有一棵树,现在给你每条树边被去掉时,形成的两个联通块中点的最大的编号分别是多少,问满足条件的树存不存在

输入格式:

第一行一个整数nnn

往下n−1n-1n−1行,每行两个整数,表示去掉这条边后两个联通块中点的最大的编号是多少

输出格式:

如果不存在满足条件的树,输出"NO"

否则输出"YES",下面n−1n-1n−1行每行描述一条树边(两端点的编号)

题目描述

Monocarp has drawn a tree (an undirected connected acyclic graph) and then has given each vertex an index. All indices are distinct numbers from 1 1 1 to n n n . For every edge e e e of this tree, Monocarp has written two numbers: the maximum indices of the vertices of the two components formed if the edge e e e (and only this edge) is erased from the tree.

Monocarp has given you a list of n−1 n - 1 n−1 pairs of numbers. He wants you to provide an example of a tree that will produce the said list if this tree exists. If such tree does not exist, say so.

输入输出格式

输入格式:

 

The first line contains one integer n n n ( 2≤n≤1000 2 \le n \le 1\,000 2≤n≤1000 ) — the number of vertices in the tree.

Each of the next n−1 n-1 n−1 lines contains two integers ai a_i ai​ and bi b_i bi​ each ( 1≤ai<bi≤n 1 \le a_i < b_i \le n 1≤ai​<bi​≤n ) — the maximal indices of vertices in the

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值