Data Structures & AlgorithmsModerateCodeforces Div2 C · ICPC regional
A tree has these parent→child edges (treat them as undirected): 20→27, 20→83, 92→20, 83→90, 27→97. 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. 11
- B. 7
- C. 13
- D. 5
Correct answer: B. 7
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): 4→59, 92→30, 92→54, 54→4, 26→99, 30→13, 26→92. For a node x, let D(x) be…
- A tree has these parent→child edges (treat them as undirected): 89→51, 30→28, 81→93, 89→4, 28→69, 68→30, 69→29, 51→81, 4→38, 38→68. For a…
- A tree has these parent→child edges (treat them as undirected): 66→92, 18→66, 66→16, 51→93, 66→79, 66→81, 18→51. For a node x, let D(x) be…
- A tree has these parent→child edges (treat them as undirected): 51→18, 33→51, 51→15, 71→19, 71→26, 7→6, 7→71, 33→7. For a node x, let D(x)…
- A tree has these parent→child edges (treat them as undirected): 8→19, 73→26, 42→45, 49→84, 45→3, 8→49, 19→73, 84→98, 42→8. For a node x…
- A tree has these parent→child edges (treat them as undirected): 24→42, 22→45, 24→30, 87→10, 31→65, 30→87, 24→31, 22→12, 45→24. For a node…