n nodes numbered 0 to n − 1, rooted at node 0. The list edges describes it: [u, v, w] is an edge of length w between u and v. Node i holds the number values[i].
Consider paths that only go down: from some node to one of its descendants (a single node is a path too). A path qualifies if the numbers on its nodes are distinct, with one allowed exception: a single value may appear exactly twice. The length of a path is the sum of its edge lengths.
Return an array of two numbers: the greatest length of a qualifying path, and the smallest number of nodes among qualifying paths of that greatest length.edges=[[0, 1, 4], [1, 2, 3], [2, 3, 5]], values=[5, 6, 5, 6] → [8, 3]
The full path 0 → 1 → 2 → 3 fails because both 5 and 6 repeat. The path 0 → 1 → 2 repeats only 5 and has length 7, while 1 → 2 → 3 repeats only 6 and has length 8. The answer is length 8 with 3 nodes.
edges=[[0, 1, 2], [0, 2, 6]], values=[7, 7, 7] → [6, 2]
The value 7 may appear twice, so 0 → 2 qualifies: length 6 with 2 nodes.
[u, v, w]edges=[[0, 1, 4], [1, 2, 3], [2, 3, 5]], values=[5, 6, 5, 6]
[8, 3]
Run checks the first 3 tests in your browser. Submit checks all 33 tests on the server, hidden ones included.