Python backtracking
\nfrom typing import List\nfrom collections import defaultdict\n\nclass Solution:\n    def solve(self, values: List[int], graph, m, max_time, curr_score, curr_n
```\nfrom typing import List\nfrom collections import defaultdict\n\nclass Solution:\n    def solve(self, values: List[int], graph, m, max_time, curr_score, curr_node, curr_time):\n        if curr_time > max_time:\n            return\n        \n        # If node we visit is 0, then valid path\n        if curr_node == 0:\n            self.max_score = max(self.max_score, curr_score)\n        \n        # Try each neighbor\n        for edge in graph[curr_node]:\n            if edge[1] + curr_time > max_time:\n                continue\n\n            # First node in the path\n            if edge[0] not in m or m[edge[0]] == 0:\n                m[edge[0]] = 1\n                curr_score += values[edge[0]]\n            else:\n                m[edge[0]] += 1\n\n            self.solve(values, graph, m, max_time, curr_score, edge[0], curr_time + edge[1])\n        \n            # Backtracking, remove from the path\n            m[edge[0]] -= 1\n            if m[edge[0]] == 0:\n                # Last node in the path\n                curr_score -= values[edge[0]]\n    \n    def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n        self.max_score = 0\n        m = {0 : 1}\n\n        # Build the graph\n        graph = defaultdict(list)\n        for edge in edges:\n            graph[edge[0]].append((edge[1], edge[2]))\n            graph[edge[1]].append((edge[0], edge[2]))\n\n        self.solve(values, graph, m, maxTime, values[0], 0, 0)\n        return self.max_score\n        \n\n\n```
['Backtracking', 'Python']