Data Structures & AlgorithmsVery hardCodeforces Div2 C · ICPC regional
A tree has these parent→child edges (treat them as undirected): 60→53, 20→16, 26→64, 51→37, 20→26, 6→51, 53→1, 6→60, 51→73, 16→6. 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. 29
- B. 21
- C. 45
- D. 10
Correct answer: B. 21
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 (treat them as undirected): 80→43, 12→54, 27→12, 51→33, 10→72, 10→27, 9→10, 80→9, 43→57, 10→92, 22→51…
- A tree has these parent→child edges (treat them as undirected): 77→90, 77→84, 90→8, 46→33, 92→10, 46→77, 10→46, 92→81, 81→15, 77→39. For a…
- A tree has these parent→child edges (treat them as undirected): 26→66, 6→39, 8→69, 34→26, 26→6, 34→58, 34→71, 34→68, 8→59, 6→40, 8→81…
- A tree has these parent→child edges (treat them as undirected): 48→16, 48→86, 99→64, 42→9, 48→91, 86→42, 86→88, 57→11, 42→57, 86→99. For a…
- A tree has these parent→child edges (treat them as undirected): 56→80, 67→4, 47→27, 12→87, 56→58, 27→72, 89→67, 27→78, 27→56, 92→89…
- 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…