Data Structures & AlgorithmsVery hardCodeforces Div2 C · ICPC regional
A tree has these parent→child edges (treat them as undirected): 69→44, 69→96, 85→69, 18→85, 12→5, 82→9, 18→82, 5→72, 96→24, 85→12. For a node x, let D(x) be the sum of the distances, in edges, from x to every node of the tree. What is the minimum value of D(x) over all nodes x?
- A. 25
- B. 41
- C. 10
- D. 20
Correct answer: D. 20
The minimum of D(x) is attained at the tree's median, which can be found by rerooting one edge at a time. The root's total, the maximum total, or the node of highest degree are not the minimum.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A tree has these parent→child edges: 26→37, 34→59, 26→34, 6→1, 34→62, 1→26. The distance between two nodes is the number of edges on the…
- A tree has these parent→child edges: 74→63, 63→39, 74→14, 63→86, 14→71. The distance between two nodes is the number of edges on the path…
- A tree has these parent→child edges: 9→78, 9→40, 40→89, 81→44, 44→9, 81→74. The distance between two nodes is the number of edges on the…
- A tree has these parent→child edges: 54→49, 49→78, 33→48, 2→67, 48→72, 43→2, 49→43, 43→85, 78→33. The distance between two nodes is the…
- A tree has these parent→child edges: 90→61, 45→87, 2→28, 61→84, 2→98, 28→51, 98→45, 98→90, 28→44, 25→2. The distance between two nodes is…
- A tree has these parent→child edges: 8→10, 8→41, 36→5, 52→91, 36→8, 5→33, 91→89, 33→17, 41→53, 36→52. The distance between two nodes is…