Python 🐍 DFS recursive with cache and  frozen set
Idea inspired from @float4, using cashe to speed up the dfs so it\'s do any unnecessary recalucations that were made before, however as cache doesn\'t work with
Idea inspired from @float4, using cashe to speed up the dfs so it\'s do any unnecessary recalucations that were made before, however as cache doesn\'t work with sets and maps, had to use a immuatble version of set --> [frozenset](https://www.programiz.com/python-programming/methods/built-in/frozenset) \n\n```\nclass Solution:\n    def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n        graph=defaultdict(list)\n        \n        for in_,out,cost in edges:\n            graph[in_].append((out,cost))\n            graph[out].append((in_,cost))\n        \n        \n        self.max_res=0\n        @cache\n        def dfs(node,time,val,seen):\n         \n            if node==0:\n                self.max_res=max(self.max_res,val)\n            \n            for neigh,t in graph[node]:\n                if time+t>maxTime:\n                      continue\n                dfs(neigh,  time+t,  val+(neigh not in seen) * values[neigh],   seen | frozenset([neigh]) )\n        dfs(0,0,values[0],frozenset([0]))\n        return self.max_res\n```
['Depth-First Search', 'Python']