Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional

A tree has these parent→child edges, with positive weights: 29→42 (weight 2), 29→65 (weight 6), 65→53 (weight 5), 36→23 (weight 4), 42→72 (weight 4), 42→36 (weight 6), 3→44 (weight 3), 53→3 (weight 3). 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)?

  1. A. 17
  2. B. 33
  3. C. 7
  4. D. 29

Correct answer: D. 29

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.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic