[英]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?
编写执行以下操作的程序: 接受以下输入: (1) 节点数 (2) 表示边的二维数组。 第 i 条边将节点 input2[0][i] 连接到节点 input2[1][i]。 假设可以在节点之间绘制一条线,如果它们之间有一条边,则打印可以在节点之间绘制的线数。
示例测试用例: input1: 4 input2: {{1,1,1},{2,3,4}} output1: 3
这看起来像是一种表示有向图的方法。 节点数表示从1
到input1
的一组节点数。 input2
然后看起来是一个二元素列表。 input2[0]
的每个元素代表一条边的起点, input2[1]
的每个对应元素代表一条边的终点。 在您的示例中,有 4 个节点(1、2、3、4),边将节点 1 连接到节点 2、3 和 4 中的每一个。
* 4
^
|
|
|
1 * --------> * 2
|
|
|
v
* 3
output 为 3,因为input2
的内容代表图中所示的三个边。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.