Codeforces Round 793 (Div. 2)
D
Circular Spanning Tree
Codeforces
2000
原题
← CE →
翻译中…

There are $n$ nodes arranged in a circle numbered from $1$ to $n$ in the clockwise order. You are also given a binary string $s$ of length $n$.

翻译中…

Your task is to construct a tree on the given $n$ nodes satisfying the two conditions below or report that such tree does not exist:

翻译中…
  • For each node $i$ $(1 \le i \le n)$, the degree of node is even if $s_i = 0$ and odd if $s_i = 1$.
  • 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 $(u, v)$ in the tree is drawn as a line segment connecting $u$ and $v$ on the circle.

翻译中…

A tree on $n$ nodes is a connected graph with $n - 1$ edges.

翻译中…

Input

翻译中…

The input consists of multiple test cases. The first line contains a single integer $t$ $(1 \leq t \leq 2\cdot 10^4)$  — the number of test cases. Description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ $(2 \leq n \leq 2\cdot 10^5)$  — the number of nodes.

翻译中…

The second line of each test case contains a binary string $s$ of length $n$.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$.

翻译中…

Output

翻译中…

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 a suitable 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 $n - 1$ lines, each containing two integers $u$ and $v$ $(1 \leq u,v \leq n, u \neq v)$ denoting an edge between $u$ and $v$ in the tree. If there are multiple possible answers, output any.

翻译中…

Note

翻译中…

In the first test case, the tree looks as follows:

翻译中…

image

翻译中…

In the second test case, there is only one possible tree with an edge between $1$ and $2$, and it does not satisfy the degree constraints.

翻译中…

In the third test case,

翻译中…

image

翻译中…

The tree on the left satisfies the degree constraints but the edges intersect internally, therefore it is not a valid tree, while the tree on the right is valid.

翻译中…

样例

Input #1
3
4
0110
2
10
6
110110
Output #1
YES
2 1
3 4
1 4
NO
YES
2 3
1 2
5 6
6 2
3 4
InputCopy OutputCopy
题目信息
题号
1682D
时间限制
1 s
内存限制
256 MB
标签
构造
模拟
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。