classSolution:defsolve(self,n:int,Tree_edge: List[Interval],Edge_value: List[int]) ->int:from collections import defaultdict# 利用字典构造无向图 g =defaultdict(list)for i inrange(n -1): x, y, v = Tree_edge[i].start, Tree_edge[i].end, Edge_value[i] g[x].append([y, v]) g[y].append([x, v])defdfs(x,parent,cur_dist): mx_id, mx_dist = x, cur_distfor sub, v in g[x]:if sub != parent:# 排除父节点 i, d =dfs(sub, x, cur_dist + v)if d > mx_dist: mx_id, mx_dist = i, dreturn mx_id, mx_dist i, _ =dfs(0, -1, 0) _, r =dfs(i, -1, 0)return r