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 all the numbers on its nodes are distinct. 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], [0, 3, 7]], values=[5, 6, 5, 8] → [7, 2]
The path 0 → 1 → 2 does not qualify: nodes 0 and 2 both hold 5. That leaves 0 → 1 (length 4), 1 → 2 (length 3) and 0 → 3 (length 7, 2 nodes), which is the best.
edges=[[0, 1, 2], [1, 2, 2], [0, 3, 4]], values=[1, 2, 3, 4] → [4, 2]
Length 4 is reached by both 0 → 1 → 2 (3 nodes) and 0 → 3 (2 nodes). The length is 4 and the smaller node count is 2.
edges=[[1, 0, 9]], values=[3, 3] → [0, 1]
Both nodes hold 3, so a path is a single node: length 0 with 1 node.
[u, v, w]edges=[[0, 1, 4], [1, 2, 3], [0, 3, 7]], values=[5, 6, 5, 8]
[7, 2]
Run checks the first 3 tests in your browser. Submit checks all 72 tests on the server, hidden ones included.