DFS | Python3 | Approach Explained
Approach\nBrute force all paths possible using a depth first search and backtracking method.\n\nWhen we traverse any path, we check if the node we are visiting 
# Approach\nBrute force all paths possible using a depth first search and backtracking method.\n\nWhen we traverse any path, we check if the node we are visiting is 0. If it is, check if the current path we are on is the max quality. \n\nWhen calculating the sum of qualities, it is important to only add them if we haven\'t visited it yet. To do this, we use a hashmap and backtracking to determine how many times we have visited a node during a traversal.\n\n# Complexity\n\n### Time complexity:\nThe constraints of the problem tell us\n1. $$10 <= timej, maxTime <= 100$$ which means we can have up to traverse up to 91 nodes\n2. There are at most four edges connected to each node.\n\nThis means at all 91 nodes, we can traverse at MOST 4 edges each. This means at most $$4^{91}$$ visits to nodes can occur.\n\nSo, the time complexity should be $$O(1)$$\n\n### Space complexity:\nWe create two objects in this algorithm: adjacency list and visited hashmap. The visited hashmap has complexity $$O(V)$$ because it tracks how many times we have visited a node. The adjacency list however is $$O(V+E)$$ since it contains edges between nodes.\n\nHence, the overall space complexity is $$O(V+E)$$ where $$V$$ represents values and $$E$$ represents edges \n\n# Code\n```\nclass Solution:\n    def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n        adj = defaultdict(set)\n        for e in edges:\n            u, v, t = e[0], e[1], e[2]\n            adj[u].add((v, t))\n            adj[v].add((u, t))\n\n        result = 0\n        visited = defaultdict(int)\n\n        def dfs(u, maxTime, quality):\n            if u == 0:\n                nonlocal result\n                result = max(result, quality)\n\n            visited[u] += 1\n            for v, t in adj[u]:\n                if maxTime - t >= 0:\n                   dfs(v, maxTime - t, quality + values[v] if v not in visited else quality)\n            visited[u] -= 1\n            if visited[u] == 0:\n                del visited[u]\n\n        dfs(0, maxTime, values[0])\n\n        return result\n```
['Depth-First Search', 'Python3']