#3425
Longest Special Path
international master · 2160 · lc hard +32 · 22.5% accepted · 126 likes · top 3%
Description
You are given an undirected tree rooted at node 0 with n nodes numbered 0 to n - 1, described by a 2D array edges of length n - 1, where edges[i] = [ui, vi, lengthi] is an edge between ui and vi with length lengthi. You are also given an integer array nums, where nums[i] is the value of node i.
A special path is a downward path from an ancestor to a descendant where all node values along the path are distinct.
A path may start and end at the same node.
Return an array result of size 2: result[0] is the length of the longest special path, and result[1] is the minimum number of nodes among all longest special paths.
Code
1
2
3