[英]Can anyone tell me what “node” is being referred to here & how is the sample test case even working? What is the exact meaning of edges in the array?
Write a program that does the following: Accept the following inputs: (1) Number of nodes (2) A 2-D array representing edges.编写执行以下操作的程序: 接受以下输入: (1) 节点数 (2) 表示边的二维数组。 ith edge connects node input2[0][i] to node input2[1][i].
第 i 条边将节点 input2[0][i] 连接到节点 input2[1][i]。 Assuming that a line can be drawn between nodes if there is an edge between them, print number of lines that can be drawn between nodes.
假设可以在节点之间绘制一条线,如果它们之间有一条边,则打印可以在节点之间绘制的线数。
Sample test case: input1: 4 input2: {{1,1,1},{2,3,4}} output1: 3示例测试用例: input1: 4 input2: {{1,1,1},{2,3,4}} output1: 3
This looks like a way to represent a directed graph.这看起来像是一种表示有向图的方法。 The number of nodes implies a set of nodes number from
1
to input1
.节点数表示从
1
到input1
的一组节点数。 input2
then appears to be a two-element list. input2
然后看起来是一个二元素列表。 Each element of input2[0]
represents the starting point of an edge, and each corresponding element of input2[1]
represents the end point. input2[0]
的每个元素代表一条边的起点, input2[1]
的每个对应元素代表一条边的终点。 In your example, there are 4 nodes (1, 2, 3, 4), with edges connecting node 1 to each of nodes 2, 3, and 4.在您的示例中,有 4 个节点(1、2、3、4),边将节点 1 连接到节点 2、3 和 4 中的每一个。
* 4
^
|
|
|
1 * --------> * 2
|
|
|
v
* 3
The output is 3 because the contents of input2
represents the three edges shown in the diagram. output 为 3,因为
input2
的内容代表图中所示的三个边。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.