File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ //! Finds the center of a weighted tree using two depth-first searches (DFS).
2+ //!
3+ //! The algorithm works as follows:
4+ //!
5+ //! 1. Perform a first DFS to compute, for each node, the maximum distance
6+ //! to any descendant in its subtree (i.e., the deepest node below it).
7+ //!
8+ //! 2. Perform a second DFS to compute, for each node, the maximum distance
9+ //! to nodes outside its subtree (i.e., through its parent and other branches).
10+ //!
11+ //! For each vertex, the farthest node in the tree is either:
12+ //! - a descendant in its own subtree, or
13+ //! - a node reached by going up to its parent and then down another branch.
14+ //!
15+ //! The eccentricity of each node is the maximum of these two values.
16+ //! The center of the tree is the node that minimizes this eccentricity.
17+ //!
18+ //! This implementation works for weighted trees.
19+
120use std:: collections:: HashMap ;
221
322use crate :: data_structures:: { graph:: Graph , UndirectedGraph } ;
You can’t perform that action at this time.
0 commit comments