python | DFS | please comment if you can optimise this approach further
\n/*\n    approach: \n    we can simply apply a dfs based approach to iterate over all the nodes\n    and keep track of the path observed so far. \n    if the c
```\n/*\n    approach: \n    we can simply apply a dfs based approach to iterate over all the nodes\n    and keep track of the path observed so far. \n    if the current node has apple, then insert all the edges observed in the path to the result set\n    once all the nodes have been traversed using the dfs, the answer will be  twice the number of edges in result set\n*/\n```\n\n```\nclass Solution:\n\n    def minTime(self, n: int, edges: List[List[int]], hasApple: List[bool]) -> int:\n        graph_map = {i: set() for i in range(n)}\n        for edge in edges:\n            graph_map[edge[0]].add(edge[1])\n            graph_map[edge[1]].add(edge[0])\n            \n        self.result = set()\n        visited = set()\n        def dfs(node, path):\n            visited.add(node)\n            if hasApple[node]:\n                temp = path + \'|\' + str(node)\n                temp = temp.split(\'|\')[1:]\n                # print(temp)\n                for i in range(1, len(temp)):\n                    self.result.add((temp[i], temp[i-1]))\n            for nei in graph_map[node]:\n                if nei not in visited: \n                    dfs(nei, path + \'|\' + str(node))\n                \n        dfs(0, "")\n        # print(self.result)        \n        return len(self.result) * 2\n```
['Depth-First Search', 'Python']