CF1714F.Build a Tree and That Is It
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A tree is a connected undirected graph without cycles. Note that in this problem, we are talking about not rooted trees.
You are given four positive integers n,d12,d23 and d31 . Construct a tree such that:
- it contains n vertices numbered from 1 to n ,
- the distance (length of the shortest path) from vertex 1 to vertex 2 is d12 ,
- distance from vertex 2 to vertex 3 is d23 ,
- the distance from vertex 3 to vertex 1 is d31 .
Output any tree that satisfies all the requirements above, or determine that no such tree exists.
输入格式
The first line of the input contains an integer t ( 1≤t≤104 ) —the number of test cases in the test.
This is followed by t test cases, each written on a separate line.
Each test case consists of four positive integers n,d12,d23 and d31 ( 3≤n≤2⋅105;1≤d12,d23,d31≤n−1 ).
It is guaranteed that the sum of n values for all test cases does not exceed 2⋅105 .
输出格式
For each test case, print YES if the suitable tree exists, and NO otherwise.
If the answer is positive, print another n−1 line each containing a description of an edge of the tree — a pair of positive integers xi,yi , which means that the i th edge connects vertices xi and yi .
The edges and vertices of the edges can be printed in any order. If there are several suitable trees, output any of them.
输入输出样例
输入#1
9 5 1 2 1 5 2 2 2 5 2 2 3 5 2 2 4 5 3 2 3 4 2 1 1 4 3 1 1 4 1 2 3 7 1 4 1
输出#1
YES 1 2 4 1 3 1 2 5 YES 4 3 2 5 1 5 5 3 NO YES 2 4 4 1 2 5 5 3 YES 5 4 4 1 2 5 3 5 YES 2 3 3 4 1 3 NO YES 4 3 1 2 2 4 NO