[Python] simple brute-force DFS | O(4^10)
We can just DFS / backtrack the graph starting from the initial node in the simplistic way. Cyclic paths are allowed because visited nodes are not filtered out 
We can just DFS / backtrack the graph starting from the initial node in the simplistic way. Cyclic paths are allowed because visited nodes are not filtered out as they are in typical graph traversal. There won\'t be stack overflow since the constraints on input are pretty small. \n\n> There are *at most four* edges connected to each node.\n\nFor every nodes, we have at most four neighbours to traverse.\n\n> `10 <= timej, maxTime <= 100`\n\n`maxTime / time_j <= 10` and hence the maximum path length is at most `10`.\n\nAt each DFS/backtracking level, we have at most 4 sub-functions to call. And the depths of DFS/backtracking are at most `10`. So we have `T = O(4^10) = O(2^20)`, which is reasonble to get accepted.\n\n\n```python\n\nfrom collections import defaultdict, Counter\n\nclass Solution:\n    def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n        g = defaultdict(dict) # construct the graph\n        for a, b, t in edges:\n            g[a][b] = t\n            g[b][a] = t\n        \n        mpq = pq = 0 # global maximal path quality, path quality of the current path\n        remaining_time = maxTime\n        visited = Counter() # nodes of the current path\n        def backtrack(node):\n            nonlocal pq, mpq, remaining_time\n            visited[node] += 1\n            if visited[node] == 1: # one more unique node\n                pq += values[node] # update path quality\n            if node == 0: # path is valid (from 0 to 0)\n                mpq = max(mpq, pq) # update maximal path quality\n            for neigh, time in g[node].items():\n                if remaining_time >= time:\n                    remaining_time -= time\n                    backtrack(neigh)\n                    remaining_time += time\n            visited[node] -= 1\n            if visited[node] == 0:\n                del visited[node]\n                pq -= values[node]\n        backtrack(0)\n        return mpq\n```
[]