Python BackTrack
\nclass Solution:\n    def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n        \n        ans, res = values[0], 0\
```\nclass Solution:\n    def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n        \n        ans, res = values[0], 0\n        nodes = defaultdict(list)\n        for x,y,c in edges:\n            nodes[x].append((y, c))\n            nodes[y].append((x, c))\n\n        def backtrack(visit, time, value):\n            nonlocal res\n            x = visit[-1]\n            if value > res and x == 0:\n                res = value\n            \n            for y,c in nodes[x]:\n                if  c + time <= maxTime:\n                    total = value + values[y] if y not in visit else value\n                    visit.append(y)\n                    backtrack(visit, c + time, total)\n                    visit.pop()\n        \n        backtrack([0], 0 , values[0])\n        return res \n                    \n```
['Backtracking', 'Python']