Data Structures & AlgorithmsHardCodeforces Div2 C · ICPC regional
A tree has these parent→child edges (treat them as undirected): 84→73, 20→88, 20→26, 88→51, 90→16, 26→90, 73→63, 70→84, 26→70, 88→25. 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. 22
- C. 46
- D. 10
Correct answer: B. 22
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): 32→35, 11→37, 36→66, 55→32, 32→36, 36→31, 37→79, 35→11, 99→55. For a node…
- A tree has these parent→child edges (treat them as undirected): 69→97, 44→65, 44→84, 65→21, 65→69, 69→9, 9→17, 9→83. For a node x, let…
- A tree has these parent→child edges (treat them as undirected): 45→2, 60→59, 2→32, 32→8, 45→60, 30→31, 8→9, 60→11, 30→45. For a node x…
- 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…
- 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…