[Python] memoized DFS
Like many other solutions, in order to memoize the backtracking, we can use a bitmask, i.e. an int holding (2**n)-1 bits. I write out as functions what we need 
Like many other solutions, in order to memoize the backtracking, we can use a bitmask, i.e. an int holding (2**n)-1 bits. I write out as functions what we need to do to a bitmask in order to run the DFS successfully\n\n```\nclass Solution:\n    def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n\n        n = len(values)\n        #values is values of ith node\n        graph = defaultdict(list)\n        for src, dest, time in edges:\n            graph[src].append((dest,time))\n            graph[dest].append((src, time))\n\n        self.ansr = 0\n        # let\'s make visited a bitmask...\n        # bitmask will be 2**n-1\n        #bitmask starts at one\n        def set_ith_bit(x, i):\n            return (1<<i)|x\n        \n        def unset_ith_bit(x, i):\n            return ~(1<<i) & x\n        \n        def check_ith_bit(x,i):\n            return (x >> i) & 1\n        \n        @lru_cache(None)\n        def backtrack(node = 0, curTime = 0, visited = 1, curval = values[0]):\n            if(curTime > maxTime):\n                return\n            for v,time in graph[node]:\n                if(curTime+time<=maxTime):    \n                    \n                    backtrack(v, curTime+time, set_ith_bit(visited, v), curval+values[v] if not check_ith_bit(visited,v) else curval)\n            if(node == 0):\n                \n                self.ansr = max(self.ansr, curval)#max(self.ansr, (sum([values[i] for i in range(n) if visited[i]>0])))\n                #print(self.ansr)\n            return\n        backtrack()\n        return self.ansr\n\t\t\n```
[]