Simple but slow(7%)
Code\n\nclass Solution:\n    def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n        d = defaultdict(list)\n     
# Code\n```\nclass Solution:\n    def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n        d = defaultdict(list)\n        for u, v, w in edges:\n            d[u].append((v, w))\n            d[v].append((u, w))\n        res = values[0]\n        q = deque([[0, 0, values[0], set([0])]])\n        while q:\n            node, time, score, visited = q.popleft()\n            if node == 0: res = max(res, score)\n            for ch, w in d[node]:\n                if time + w <=maxTime:\n                    vis = visited.copy()\n                    vis.add(ch)\n                    k = 0 if ch in visited else values[ch]\n                    q.append([ch, time+w, score+k, vis])\n        return res\n```
['Python3']