Problem
Figure 2. A labeled tree with 6 vertices and 5 edges.
An undirected graph is connected if there is a path connecting any two nodes. A tree is a connected (undirected) graph containing no cycles; this definition forces the tree to have a branching structure organized around a central core of nodes, just like its living counterpart. See Figure 2.
We have already grown familiar with trees in “Mendel's First Law”, where we introduced the probability tree diagram to visualize the outcomes of a random variable.
In the creation of a phylogeny, taxa are encoded by the tree's leaves, or nodes having degree 1. A node of a tree having degree larger than 1 is called an internal node.
Given: A positive integer () and an adjacency list corresponding to a graph on nodes that contains no cycles.
Return: The minimum number of edges that can be added to the graph to produce a tree.
无向图的连接,如果有一个路径连接的任意两个节点。甲树是不包含一个连接(无向)图个循环; 此定义迫使树具有围绕节点的中心核心组织的分支结构,就像其活动副本一样。参见图2。
我们已经长大熟悉树“孟德尔第一定律”,在这里我们引入了概率树图 以可视化的结果一的随机变量。
在系统发育的创建中,分类单元由树的叶子或具有度1的节点编码。树的度大于1的节点称为内部节点。
给定:与不包含循环的节点上的图相对应的正整数()和邻接表。
返回值:可以添加到图中以生成树的最小边数。
Sample Dataset
10 1 2 2 8 4 10 5 9 6 10 7 9
Sample Output
3