Python Hard
```python3 []
class Solution:
    def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:
        '''
        2000 edges

        There are at most four edges connected to each node.

        we want to maximize score

        score is sum of unique nodes


        simple dp

        except how do we keep 
        '''
        lookup = defaultdict(list)
 

        for u, v, w in edges:
            lookup[u].append((v, w))
            lookup[v].append((u, w))


        INF = 10 ** 10
        

        @cache
        def calc(node, time, mask):
            best = -INF
            if node == 0:
                best = 0

            
            for v, w in lookup[node]:
                if w <= time:
                    if (1 << v) & mask:
                        best = max(best, calc(v, time - w, mask))
                    else:
                        best = max(best, calc(v, time - w, (1 << v) | mask) + values[v])


            return best

        return calc(0, maxTime, 1) + values[0]

        




        
```
['Python3']