Data Structures & AlgorithmsVery hardCodeforces Div2 C · ICPC regional
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, 87→47, 12→92. 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. 38
- B. 70
- C. 34
- D. 35
Correct answer: C. 34
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): 69→44, 69→96, 85→69, 18→85, 12→5, 82→9, 18→82, 5→72, 96→24, 85→12. For a…
- 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…