Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
任何人都可以通过使用递归深度优先搜索来帮助我找到树的高度吗?即找到最深的分支节点?谢谢
伪代码:
dfs( v ) : 1.visited [ v ] = true 2. max_child_depth = 0 3. 对于每个u st 都有边 (v,u) 如果未访问 [u] 那么max_child_depth = max( max_child_depth, dfs( u )) 4 . 返回max_child_depth + 1