[Solution] Tree Recovery Codeforces Solution | Codeforces Problem Solution 2022
Fishingprince loves trees. A tree is a connected undirected graph without cycles.
Fishingprince has a tree of vertices. The vertices are numbered through . Let denote the shortest distance on the tree from vertex to vertex , assuming that the length of each edge is .
However, the tree was lost in an accident. Fortunately, Fishingprince still remembers some information about the tree. More specifically, for every triple of integers (, ) he remembers whether or not.
Help him recover the structure of the tree, or report that no tree satisfying the constraints exists.
Each test contains multiple test cases. The first line contains the number of test cases (). Description of the test cases follows.
The first line of each test case contains an integer () — the number of vertices in the tree.
Then lines follow. The -th line of these lines contains strings of length consisting of 0 and 1. If the -th character in the -th string of the -th line is 0, it means that ; if the -th character in the -th string of the -th line is 1, it means that .
It is guaranteed that in one input file,
- there are at most test cases that have ;
- there are at most test cases that have .
For each test case:
- if no answer exists, output No;
- otherwise, on the first line output Yes. Then output lines. Each line should contain two integers (), denoting an edge between vertices and 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