[Solution] Circular Spanning Tree Codeforces Solution | Codeforces Problem Solution 2022
There are nodes arranged in a circle numbered from to in the clockwise order. You are also given a binary string of length .
Your task is to construct a tree on the given nodes satisfying the two conditions below or report that there such tree does not exist:
- For each node , the degree of node is even if and odd if .
- No two edges of the tree intersect internally in the circle. The edges are allowed to intersect on the circumference.
Note that all edges are drawn as straight line segments. For example, edge in the tree is drawn as a line segment connecting and on the circle.
The input consists of multiple test cases. The first line contains a single integer — the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer — the number of nodes.
The second line of each test case contains a binary string of length .
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, if there does not exist a tree that satisfies the given conditions, then output "NO" (without quotes), otherwise output "YES" followed by the description of tree.
You can output each letter in any case (for example, "YES", "Yes", "yes", "yEs", "yEs" will be recognized as a positive answer).
If there exists a tree, then output lines, each containing two integers and denoting an edge between and in the tree. If there are multiple possible answers, output any.
No comments:
Post a Comment