[英]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.