GUPTA MECHANICAL

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

Saturday 25 June 2022

[Solution] Tree Recovery Codeforces Solution | Codeforces Problem Solution 2022


F. Tree Recovery
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output

Fishingprince loves trees. A tree is a connected undirected graph without cycles.

Fishingprince has a tree of n vertices. The vertices are numbered 1 through n. Let d(x,y) denote the shortest distance on the tree from vertex x to vertex y, assuming that the length of each edge is 1.

However, the tree was lost in an accident. Fortunately, Fishingprince still remembers some information about the tree. More specifically, for every triple of integers x,y,z (1x<yn1zn) he remembers whether d(x,z)=d(y,z) or not.

Help him recover the structure of the tree, or report that no tree satisfying the constraints exists.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1t200). Description of the test cases follows.

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇


The first line of each test case contains an integer n (2n100) — the number of vertices in the tree.

Then n1 lines follow. The i-th line of these n1 lines contains ni strings of length n consisting of 0 and 1. If the k-th character in the j-th string of the i-th line is 0, it means that d(i,k)d(i+j,k); if the k-th character in the j-th string of the i-th line is 1, it means that d(i,k)=d(i+j,k).

It is guaranteed that in one input file,

  • there are at most 2 test cases that have n>50;
  • there are at most 5 test cases that have n>20.
Output

For each test case:

  • if no answer exists, output No;
  • otherwise, on the first line output Yes. Then output n1 lines. Each line should contain two integers x,y (1x,yn), denoting an edge between vertices x and y of the tree. If there are multiple solutions, print any.

When printing Yes and No, you can print each letter in any case (upper or lower).

No comments:

Post a Comment