[Python] Commented DFS Solution | Concise
\nclass Solution:\n    def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n        # Creating an adjaceny list \n    
```\nclass Solution:\n    def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n        # Creating an adjaceny list \n        G = defaultdict(list)\n        for u,v,w in edges:\n            G[u].append([v,w])\n            G[v].append([u,w])\n            \n        def dfs(current, path, left):\n            # We calculate the total path quality when we reach Node 0\n            # So the most trivial case would be when we just call dfs() the first time\n            # Later on, if we end up tracking back to Node 0 Again, we have a candidate for a "valid path"\n            # So we add up values for all the nodes in the set\n            # We continue our dfs() until we have some time left\n            if current == 0:\n                tmp = 0\n                for node in path:\n                    tmp += values[node]\n                self.best = max(self.best, tmp)\n            # Moving to neighbour nodes and calling dfs() until time left\n            for nei, wei in G[current]:\n                if wei <= left:\n                    dfs(nei, {nei} | path, left - wei)\n        \n        self.best = 0\n        # Calling helper dfs() method\n        # arguments signify : current node, current path set, time left \n        dfs(0, {0}, maxTime)\n        return self.best\n```
['Depth-First Search', 'Python']