Java Solution
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```java []\nclass Solution {\n    int[] distance2;\n    int[] distance1;\n    public int[] maxTargetNodes(int[][] edges1, int[][] edges2, int k) {\n\n        List<List<Integer>> adj1 = new ArrayList<>();\n        List<List<Integer>> adj2 = new ArrayList<>();\n\n        for(int i=0;i<edges1.length+1;i++)\n        {\n             adj1.add(new ArrayList<>());\n        }\n\n        for(int[] edge:edges1)\n        {\n             adj1.get(edge[0]).add(edge[1]);\n            adj1.get(edge[1]).add(edge[0]);\n        }\n\n        for(int i=0;i<edges2.length+1;i++)\n        {\n             adj2.add(new ArrayList<>());\n        }\n\n        for(int[] edge:edges2)\n        {\n            adj2.get(edge[0]).add(edge[1]);\n            adj2.get(edge[1]).add(edge[0]);\n        }\n\n        int[] ans = new int[edges1.length+1];\n\n        distance1 = new int[adj1.size()];\n        for(int i=0;i<distance1.length;i++)\n        {\n            distance1[i] = bfs(i,k,adj1);\n        }\n\n        distance2 = new int[adj2.size()];\n        for(int i=0;i<distance2.length;i++)\n        {\n            distance2[i] = bfs(i,k-1,adj2);\n        }\n\n        int val = Integer.MIN_VALUE;\n        for(int j=0;j<distance2.length;j++)\n        {\n            val = Math.max(val,distance2[j]);\n        }\n\n        for(int i=0;i<ans.length;i++)\n        {\n            ans[i]=distance1[i];\n            ans[i]+=val;\n        }\n\n        return ans;\n        \n    }\n\n    \n\n    public int bfs(int i,int k, List<List<Integer>> adj)\n    {\n        int ans = 0;\n        Queue<int[]> queue = new LinkedList<>();\n        queue.add(new int[]{i,0});\n        int count = 0;\n        HashSet<Integer> visited = new HashSet<>();\n        visited.add(i);\n\n        while(queue.size()>0)\n        {\n             int[] curr = queue.poll();\n            if(curr[1]>k)\n            {\n                continue;\n            }\n            count+=1;\n\n            for(Integer j:adj.get(curr[0]))\n            {\n                 if(!visited.contains(j))\n                 {\n                     queue.add(new int[]{j,curr[1]+1});\n                     visited.add(j);\n                 }\n            }\n            \n        }\n\n        return count;\n    }\n}\n```
['Breadth-First Search', 'Java']