Python (Simple DFS)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n    def maxTargetNodes(self, edges1, edges2, k):\n        n, m, graph1, graph2 = len(edges1)+1, len(edges2)+1, defaultdict(list), defaultdict(list)\n\n        for i,j in edges1:\n            graph1[i].append(j)\n            graph1[j].append(i)\n\n        for i,j in edges2:\n            graph2[i].append(j)\n            graph2[j].append(i)\n\n        def function(node,graph,d):\n            stack, ans, visited = [(node,0)], {node}, {node}\n\n            while stack:\n                nd,dist = stack.pop()\n\n                if dist <= d:\n                    ans.add(nd)\n\n                for neighbor in graph[nd]:\n                    if neighbor not in visited:\n                        stack.append((neighbor,dist+1))\n                        visited.add(neighbor)\n\n            return len(ans)\n\n        res1 = [function(i,graph1,k) for i in range(n)]\n        res2 = max([function(i,graph2,k-1) for i in range(m)])\n\n        return [i+res2 for i in res1] if k > 0 else [1]*n\n```
['Python3']