CF1868D.Flower-like Pseudotree

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A pseudotree is a connected graph which has exactly one cycle and no self-loops. Note that a pseudotree may contain multiple-edges. It can be shown that a pseudotree with nn vertices always contains nn edges.

After deleting all edges on the cycle in the pseudotree, a forest†^{\dagger} will be formed. It can be shown that each tree in the forest will contain exactly one vertex which is on cycle before removing the edges. If all trees in the forest have the same depth‡^{\ddagger} when picking the vertex on cycle as root, we call the original pseudotree flower-like.

Our friend sszcdjr, had a flower-like pseudotree with nn vertices and nn edges. However, he forgot all the edges in the pseudotree. Fortunately, he still remembers the degrees of vertices. Specifically, the degree of the ii-th vertex is did_i.

You have to help sszcdjr construct a possible flower-like pseudotree with nn vertices, where the degree of the ii-th vertex is exactly did_i, or tell him that it is impossible.

†^{\dagger} A forest is a graph in which all connectivity components are trees. A connected graph without cycles and self-loops is called a tree.

‡^{\ddagger} The depth of a tree with a root is the maximum distance from the root to the vertex of this tree.

伪树(pseudotree)是一个连通图,它恰好包含一个环,且不含自环。注意:伪树允许存在重边。可以证明,一个含 nn 个顶点的伪树必然恰好含有 nn 条边。

在伪树中删除环上的所有边后,将得到一片森林†^{\dagger}。可以证明,该森林中的每一棵树都恰好包含一个原先位于环上的顶点。若以该环上顶点为根时,森林中所有树的深度‡^{\ddagger}均相等,则称原伪树为“花状”(flower-like)。

我们的朋友 sszcdjr 拥有一棵含 nn 个顶点、nn 条边的花状伪树。但他忘记了该伪树的所有边。幸运的是,他仍记得各顶点的度数:第 ii 个顶点的度数为 did_i。

你需要帮助 sszcdjr 构造一棵可能的、含 nn 个顶点的花状伪树,使得第 ii 个顶点的度数恰好为 did_i;若不存在这样的伪树,则告知其不可能。

†^{\dagger} 森林(forest)是指其每个连通分量均为树的图。不含环与自环的连通图称为树(tree)。

‡^{\ddagger} 以某顶点为根的树的深度,定义为该根到树中任意顶点的最大距离。

输入格式

The first line of the input contains a single integer tt (1≤t≤1051\leq t\leq 10^5) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn (2≤n≤1062\leq n\leq 10^6) — the number of vertices.

The second line of each test case contains nn integers d1,d2,…,dnd_1,d_2,\ldots,d_n (1≤di≤n1\leq d_i\leq n) — the degree of each vertex.

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6.

输入的第一行包含一个整数 tt(1≤t≤1051\leq t\leq 10^5)—— 表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤1062\leq n\leq 10^6)—— 表示顶点的数量。

每个测试用例的第二行包含 nn 个整数 d1,d2,…,dnd_1,d_2,\ldots,d_n(1≤di≤n1\leq d_i\leq n)—— 表示每个顶点的度数。

保证所有测试用例中 nn 的总和不超过 10610^6。

输出格式

For each test case, if there exist a possible flower-like pseudotree:

  • Print "Yes" (without quotes) in the first line.
  • Then, output nn lines, in each line print two integers uiu_i and viv_i — the two vertices that the ii-th edge connects.

If there are multiple answers, you may output any of them.

Otherwise, print "No" (without quotes) in the only line of output.

You can output the first line of each test case in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

对于每个测试用例,如果存在一个可能的花形伪树:

  • 在第一行输出 "Yes"(不带引号);
  • 然后输出 nn 行,每行输出两个整数 uiu_i 和 viv_i —— 表示第 ii 条边所连接的两个顶点。

若存在多个合法答案,输出任意一个即可。

否则,在输出的唯一一行中输出 "No"(不带引号)。

每个测试用例的第一行可使用任意大小写形式(大写或小写)。例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均会被识别为肯定回答。

输入输出样例

  • 输入#1

    6
    3
    2 2 2
    4
    1 2 3 4
    7
    4 3 3 1 1 1 1
    6
    1 1 2 2 3 3
    10
    1 1 5 2 1 1 1 1 1 6
    9
    1 1 3 1 1 4 1 1 5

    输出#1

    Yes
    1 2
    2 3
    3 1
    No
    Yes
    1 2
    2 3
    3 1
    1 4
    1 5
    2 6
    3 7
    Yes
    5 6
    6 5
    1 3
    2 4
    3 5
    4 6
    No
    Yes
    3 6
    6 9
    9 3
    1 3
    2 6
    4 6
    5 9
    7 9
    8 9

说明/提示

In the first test case, the only possible flower-like psuedotree is:

After deleting all edges on the cycle in the pseudotree, each tree has depth 00.

In the second test case, it can be proven that there's no such flower-like psuedotree.

In the third test case, one of the possible flower-like psuedotrees is:

在第一个测试用例中,唯一可能的花状伪树为:

在该伪树中删除环上的所有边后,每棵生成树的深度均为 00。

在第二个测试用例中,可以证明不存在这样的花状伪树。

在第三个测试用例中,一个可能的花状伪树为:

输入解题思路,AI测评打分。不知道怎么写?

首页