Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional
A tree has these parent→child edges, with positive weights: 78→31 (weight 8), 93→37 (weight 3), 15→40 (weight 3), 81→43 (weight 6), 66→78 (weight 6), 67→66 (weight 1), 93→81 (weight 6), 66→60 (weight 3), 93→98 (weight 4), 15→80 (weight 6), 37→15 (weight 2), 93→67 (weight 6). The weight of a path is the sum of its edge weights. What is the largest weight of any path in the tree (the weighted diameter)?
- A. 21
- B. 54
- C. 33
- D. 7
Correct answer: C. 33
The weighted diameter is found by two searches: from any node go to the farthest node, then from that node to the farthest again. The farthest node from the root, the total weight, or the edge count are different numbers.
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, with positive weights: 84→19 (weight 2), 35→69 (weight 8), 50→73 (weight 3), 50→44 (weight 4), 94→50…
- A tree has these edges (given as parent→child; ignore the direction): 82→41, 54→80, 65→82, 80→95, 38→54, 80→67, 67→65. The eccentricity of…
- A tree has these edges (given as parent→child; ignore the direction): 78→50, 50→80, 40→98, 78→30, 97→78, 80→73, 40→97. The eccentricity of…
- A tree has these edges (given as parent→child; ignore the direction): 38→54, 81→67, 81→51, 31→81, 72→53, 51→62, 51→38, 72→31. The…
- A tree has these edges (given as parent→child; ignore the direction): 92→25, 93→98, 27→54, 27→73, 98→27, 98→40, 73→81, 92→57, 27→92. The…
- A tree has these edges (given as parent→child; ignore the direction): 97→22, 53→38, 38→28, 81→44, 28→35, 22→53, 22→2, 22→46, 53→81, 35→54…