[Solution] Build a Tree and That Is It Codeforces Solution
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 and . Construct a tree such that:
- it contains vertices numbered from to ,
- the distance (length of the shortest path) from vertex to vertex is ,
- distance from vertex to vertex is ,
- the distance from vertex to vertex is .
Output any tree that satisfies all the requirements
occupied
above, or determine that no such tree exists.
The first line of the input contains an integer () —the number of test cases in the test.
This is followed by test cases, each written on a separate line.
Each test case consists of four positive integers and ().
It is guaranteed that the sum of values for all test cases does not exceed .
For each test case, print YES if the suitable tree exists, and NO otherwise.
If the answer is positive, print another line each containing a description of an edge of the tree — a pair of positive integers , which means that the th edge connects vertices and .
The edges and vertices of the edges can be printed in any order. If there are several suitable trees, output any of them.
No comments:
Post a Comment