GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Tuesday 2 August 2022

[Solution] Build a Tree and That Is It Codeforces Solution



F. Build a Tree and That Is It
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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

Solution Click Below:-  👉CLICK HERE👈

👇👇👇👇👇

 occupied

 above, or determine that no such tree exists.

Input

The first line of the input contains an integer t (1t104) —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 (3n2105;1d12,d23,d31n1).

It is guaranteed that the sum of n values for all test cases does not exceed 2105.

Output

For each test case, print YES if the suitable tree exists, and NO otherwise.

If the answer is positive, print another n1 line each containing a description of an edge of the tree — a pair of positive integers xi,yi, which means that the ith 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.

No comments:

Post a Comment