CF1710D.Recover the Tree

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Rhodoks has a tree with nn vertices, but he doesn't remember its structure. The vertices are indexed from 11 to nn.

A segment [l,r][l,r] (1≤l≤r≤n1 \leq l \leq r \leq n) is good if the vertices with indices ll, l+1l + 1, ..., rr form a connected component in Rhodoks' tree. Otherwise, it is bad.

For example, if the tree is the one in the picture, then only the segment [3,4][3,4] is bad while all the other segments are good.

For each of the n(n+1)2\frac{n(n+1)}{2} segments, Rhodoks remembers whether it is good or bad. Can you help him recover the tree? If there are multiple solutions, print any.

It is guaranteed that the there is at least one tree satisfying Rhodoks' description.

罗多克斯有一棵包含 nn 个顶点的树,但他不记得其具体结构了。这些顶点编号为 11 到 nn。

若编号为 l,l+1,…,rl, l+1, \dots, r(其中 1≤l≤r≤n1 \leq l \leq r \leq n)的顶点在罗多克斯的树中构成一个连通块,则称区间 [l,r][l,r] 是好的;否则称为坏的。

例如,若树的结构如图所示,则只有区间 [3,4][3,4] 是坏的,其余所有区间均为好的。

对于全部 n(n+1)2\frac{n(n+1)}{2} 个区间,罗多克斯都记得每个区间是好还是坏。你能帮他还原出这棵树吗?如果存在多种可能的解,输出任意一种即可。

题目保证至少存在一棵满足罗多克斯描述的树。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤10001 \leq t \leq 1000). The description of the test cases follows.

The first line of each test case contains an integer nn (1≤n≤20001 \leq n \leq 2000) — the number of vertices in the tree.

Then nn lines follow. The ii-th of these lines contains a string goodigood_i of length n+1−in+1-i consisting of 0 and 1. If the segment [i,i+j−1][i,i+j-1] is good then the jj-th character of goodigood_i is 1, otherwise jj-th character of goodigood_i is 0.

It is guaranteed that the there is at least one tree consistent with the given data.

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

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤10001 \leq t \leq 1000)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤20001 \leq n \leq 2000)——表示树中顶点的数量。

接下来是 nn 行。其中第 ii 行包含一个长度为 n+1−in+1-i 的字符串 goodigood_i,该字符串仅由字符 0 和 1 组成。若区间 [i,i+j−1][i,i+j-1] 是“好”的,则 goodigood_i 的第 jj 个字符为 1;否则为 0。

保证至少存在一棵树与给定数据一致。

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

输出格式

For each test case, print n−1n-1 lines describing the tree you recover.

The ii-th line should contain two integers uiu_i and viv_i (1≤ui,vi≤n1 \leq u_i,v_i \leq n), denoting an edge between vertices uiu_i and viv_i.

If there are multiple solutions, print any.

对于每个测试用例,输出 n−1n-1 行,描述你恢复出的树。

第 ii 行应包含两个整数 uiu_i 和 viv_i(1≤ui,vi≤n1 \leq u_i,v_i \leq n),表示顶点 uiu_i 与 viv_i 之间的一条边。

若存在多种解,输出任意一种即可。

输入输出样例

  • 输入#1

    3
    4
    1111
    111
    10
    1
    6
    111111
    11111
    1111
    111
    11
    1
    12
    100100000001
    11100000001
    1000000000
    100000000
    10010001
    1110000
    100000
    10000
    1001
    111
    10
    1

    输出#1

    1 2
    2 3
    2 4
    1 2
    2 3
    3 4
    4 5
    5 6
    2 3
    6 7
    10 11
    2 4
    6 8
    10 12
    1 4
    5 8
    9 12
    5 12
    2 12

说明/提示

The first test case is explained in the statement.

In the second test case, one possible tree is as follows:

In the third test case, one possible tree is as follows:

第一个测试用例已在题目描述中说明。

在第二个测试用例中,一种可能的树如下所示:

在第三个测试用例中,一种可能的树如下所示:

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

首页