python
Code\n\nclass Solution:\n    def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n        graph = defaultdict(list)\n\
# Code\n```\nclass Solution:\n    def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n        graph = defaultdict(list)\n\n        for i, j, k in edges:\n            graph[i].append((j, k))\n            graph[j].append((i, k))\n\n        def dfs(root, values, s, t):\n\n            ans = -float(\'inf\')\n            if root == 0:\n                ans = max(ans, s)\n                \n            for nei, time in graph[root]:\n                t_ = values[nei]\n                values[nei] = 0\n\n                if t+time>maxTime:\n                    if root == 0:\n                        ans = max(ans, s)\n                else:\n                    ans = max(ans, dfs(nei, values, s+t_, t+time))\n\n                values[nei] = t_\n            \n            return ans\n        \n        t = values[0]\n        values[0] = 0\n\n        return dfs(0, values, t, 0)\n        \n\n```
['Python3']