Tree diameter maximum weight path
Your task
Given a weighted tree with n nodes (0-indexed) as an edge list of [u, v, w], return the diameter: the maximum total weight of any simple path between two nodes. 1 <= n <= 5000, 1 <= w <= 1000. For n==1 the diameter is 0.
Examples
tree_diameter(n: int, edges: list[list[int]]) -> intExample 1
Input
tree_diameter(4, [[0, 1, 1], [1, 2, 1], [1, 3, 1]])Output
2