CF1761C.Set Construction

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given a binary matrix bb (all elements of the matrix are 00 or 11 ) of nn rows and nn columns.

You need to construct a nn sets A1,A2,,AnA_1, A_2, \ldots, A_n , for which the following conditions are satisfied:

  • Each set is nonempty and consists of distinct integers between 11 and nn inclusive.
  • All sets are distinct.
  • For all pairs (i,j)(i,j) satisfying 1i,jn1\leq i, j\leq n , bi,j=1b_{i,j}=1 if and only if AiAjA_i\subsetneq A_j . In other words, bi,jb_{i, j} is 11 if AiA_i is a proper subset of AjA_j and 00 otherwise.

Set XX is a proper subset of set YY , if XX is a nonempty subset of YY , and XYX \neq Y .

It's guaranteed that for all test cases in this problem, such nn sets exist. Note that it doesn't mean that such nn sets exist for all possible inputs.

If there are multiple solutions, you can output any of them.

输入格式

Each test contains multiple test cases. The first line contains a single integer tt ( 1t10001\le t\le 1000 ) — the number of test cases. The description of test cases follows.

The first line contains a single integer nn ( 1n1001\le n\le 100 ).

The following nn lines contain a binary matrix bb , the jj -th character of ii -th line denotes bi,jb_{i,j} .

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

It's guaranteed that for all test cases in this problem, such nn sets exist.

输出格式

For each test case, output nn lines.

For the ii -th line, first output sis_i (1sin)(1 \le s_i \le n) — the size of the set AiA_i . Then, output sis_i distinct integers from 11 to nn — the elements of the set AiA_i .

If there are multiple solutions, you can output any of them.

It's guaranteed that for all test cases in this problem, such nn sets exist.

输入输出样例

  • 输入#1

    2
    4
    0001
    1001
    0001
    0000
    3
    011
    001
    000

    输出#1

    3 1 2 3
    2 1 3
    2 2 4
    4 1 2 3 4
    1 1
    2 1 2
    3 1 2 3

说明/提示

In the first test case, we have A1={1,2,3},A2={1,3},A3={2,4},A4={1,2,3,4}A_1 = \{1, 2, 3\}, A_2 = \{1, 3\}, A_3 = \{2, 4\}, A_4 = \{1, 2, 3, 4\} . Sets A1,A2,A3A_1, A_2, A_3 are proper subsets of A4A_4 , and also set A2A_2 is a proper subset of A1A_1 . No other set is a proper subset of any other set.

In the second test case, we have A1={1},A2={1,2},A3={1,2,3}A_1 = \{1\}, A_2 = \{1, 2\}, A_3 = \{1, 2, 3\} . A1A_1 is a proper subset of A2A_2 and A3A_3 , and A2A_2 is a proper subset of A3A_3 .

首页