#abc343b. B - Adjacency Matrix
B - Adjacency Matrix
Score: points
问题描述
存在一个简单的无向图 ,包含 个顶点,分别用数字 标记。
你已知图 的邻接矩阵 。即,当且仅当 时,图 中存在一条连接顶点 和顶点 的边。
对于每个 ,请按 升序 打印顶点 直接相连的所有顶点的编号。
这里,我们称顶点 和 是直接相连的,当且仅当存在一条连接顶点 和顶点 的边。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a simple undirected graph with vertices labeled with numbers .
You are given the adjacency matrix of . That is, has an edge connecting vertices and if and only if .
For each , print the numbers of the vertices directly connected to vertex in ascending order.
Here, vertices and are said to be directly connected if and only if there is an edge connecting vertices and .
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the numbers of the vertices directly connected to vertex 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 is directly connected to vertices and . Thus, the first line should contain and in this order.
Similarly, the second line should contain and in this order, the third line should contain , and the fourth line should contain .
Sample Input 2
2
0 0
0 0
Sample Output 2
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