#abc343b. B - Adjacency Matrix

B - Adjacency Matrix

Score: 150150 points

问题描述

存在一个简单的无向图 GG,包含 NN 个顶点,分别用数字 1,2,,N1, 2, \ldots, N 标记。

你已知图 GG 的邻接矩阵 (Ai,j)(A_{i,j})。即,当且仅当 Ai,j=1A_{i,j} = 1 时,图 GG 中存在一条连接顶点 ii 和顶点 jj 的边。

对于每个 i=1,2,,Ni = 1, 2, \ldots, N,请按 升序 打印顶点 ii 直接相连的所有顶点的编号。

这里,我们称顶点 iijj 是直接相连的,当且仅当存在一条连接顶点 ii 和顶点 jj 的边。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There is a simple undirected graph GG with NN vertices labeled with numbers 1,2,,N1, 2, \ldots, N.

You are given the adjacency matrix (Ai,j)(A_{i,j}) of GG. That is, GG has an edge connecting vertices ii and jj if and only if Ai,j=1A_{i,j} = 1.

For each i=1,2,,Ni = 1, 2, \ldots, N, print the numbers of the vertices directly connected to vertex ii in ascending order.

Here, vertices ii and jj are said to be directly connected if and only if there is an edge connecting vertices ii and jj.

Constraints

  • 2N1002 \leq N \leq 100
  • Ai,j{0,1}A_{i,j} \in \lbrace 0,1 \rbrace
  • Ai,i=0A_{i,i} = 0
  • Ai,j=Aj,iA_{i,j} = A_{j,i}
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN

A1,1A_{1,1} A1,2A_{1,2} \ldots A1,NA_{1,N}

A2,1A_{2,1} A2,2A_{2,2} \ldots A2,NA_{2,N}

\vdots

AN,1A_{N,1} AN,2A_{N,2} \ldots AN,NA_{N,N}

Output

Print NN lines. The ii-th line should contain the numbers of the vertices directly connected to vertex ii in ascending order, separated by a space.

Sample Input 1

4
0 1 1 0
1 0 0 1
1 0 0 0
0 1 0 0

Sample Output 1

2 3
1 4
1
2

Vertex 11 is directly connected to vertices 22 and 33. Thus, the first line should contain 22 and 33 in this order.

Similarly, the second line should contain 11 and 44 in this order, the third line should contain 11, and the fourth line should contain 22.

Sample Input 2

2
0 0
0 0

Sample Output 2

GG may have no edges.

Sample Input 3

5
0 1 0 1 1
1 0 0 1 0
0 0 0 0 1
1 1 0 0 1
1 0 1 1 0

Sample Output 3

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

update @ 2024/3/10 01:15:35