Simple python3 solution | DFS + Counting
Complexity\n- Time complexity: O(n^2 + m^2)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n + m)\n Add your space complexity here, e.g. O
# Complexity\n- Time complexity: $$O(n^2 + m^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n + m)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n    def maxTargetNodes(self, edges1: List[List[int]], edges2: List[List[int]], k: int) -> List[int]:\n        def get_vs(edges):\n            vs = defaultdict(list)\n            for u, v in edges:\n                vs[u].append(v)\n                vs[v].append(u)\n            return vs, len(vs)\n                \n        vs_1, n = get_vs(edges1)\n        if k == 0:\n            return [1] * n\n        vs_2, m = get_vs(edges2)\n\n        def dfs(node, vs, distance):\n            stack = [(node, distance)]\n            in_progress = {node}\n            while stack:\n                u, dist = stack.pop()\n                if dist == 0:\n                    continue\n                for v in vs[u]:\n                    if v not in in_progress:\n                        in_progress.add(v)\n                        stack.append((v, dist - 1))\n            return len(in_progress)\n\n        second_max = max(\n            dfs(node, vs_2, k - 1)\n            for node in range(m)\n        )\n\n        return [\n            dfs(node, vs_1, k) + second_max\n            for node in range(n)\n        ]\n```
['Depth-First Search', 'Graph', 'Counting', 'Python3']