#3486

Longest Special Path II

grandmaster · 2235 · lc hard +32 · 18.6% accepted · 33 likes · top 1%

Description

An undirected weighted tree with n nodes (rooted at 0) is given via edges[i] = [ui, vi, lengthi] and a node-value array nums.

A "special path" goes downward from ancestor to descendant with all node values distinct, except one value may repeat at most once.

Return [result[0], result[1]] where result[0] is the maximum length of any special path and result[1] is the minimum node count among all longest special paths.

Code

1
2
3