Problem 3486 · Hard

Longest Special Path II

In a weighted tree rooted at node 0 with a value on each node, consider downward paths whose values are all different except that one value may occur twice. Report the greatest path length and, among paths of that length, the fewest nodes.

Open the interactive visualisation