[Python 3] DFS+BackTrack
\tclass Solution:\n\t\tdef maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n\t\t\tn=len(values)\n\t\t\tG=[[] for _ in 
\tclass Solution:\n\t\tdef maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n\t\t\tn=len(values)\n\t\t\tG=[[] for _ in range(n)]\n\t\t\tfor u,v,t in edges:\n\t\t\t\tG[u].append([v,t])\n\t\t\t\tG[v].append([u,t])\n\t\t\tself.res=0\n\t\t\tdef dfs(node,time,path,val):\n\t\t\t\tif node==0:\n\t\t\t\t\tself.res=max(self.res,val)\n\t\t\t\tfor child,t in G[node]:\n\t\t\t\t\tif time+t<=maxTime\n\t\t\t\t\t\tif child in path:\n\t\t\t\t\t\t\tdfs(child,time+t,path,val)\n\t\t\t\t\t\telse:\n\t\t\t\t\t\t\tpath.add(child)\n\t\t\t\t\t\t\tdfs(child,time+t,path,val+values[child])\n\t\t\t\t\t\t\tpath.remove(child)\n\t\t\tdfs(0,0,set([0]),values[0])\n\t\t\treturn self.res
[]