Simple BFS 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```cpp []\nclass Solution {\npublic:\n\n    int bfs(vector<vector<int>>& adj,int index,int k,int n)\n    {\n        vector<int> visited(n+1,0);\n        queue<int> q;\n        q.push(index);\n        int ans = 1;\n        visited[index] = 1;\n        while(!q.empty())\n        {\n            int count = q.size();\n            if(!count || !k)\n                break;\n            k--;\n            while(count--)\n            {\n                int curr = q.front();\n                q.pop();\n                for(auto node:adj[curr])\n                {\n                    if(!visited[node])\n                    {\n                        ans++;\n                        q.push(node);\n                        visited[node]=1;\n                    }\n                }   \n            }\n        }\n        return ans;\n    }\n\n\n    vector<int> maxTargetNodes(vector<vector<int>>& edges1, vector<vector<int>>& edges2, int k) {\n        \n        int n = edges1.size();\n        int m = edges2.size();\n        vector<int> ans(n+1,1);\n\n        if(k==0)\n            return ans;\n\n        vector<vector<int>> adj1(n+1);\n        vector<vector<int>> adj2(m+1);\n\n        for(auto edge:edges1)\n        {\n            adj1[edge[0]].push_back(edge[1]);\n            adj1[edge[1]].push_back(edge[0]);\n        }\n\n        for(auto edge:edges2)\n        {\n            adj2[edge[0]].push_back(edge[1]);\n            adj2[edge[1]].push_back(edge[0]);\n        }\n\n        int target = 0;\n        for(int i=0;i<=m;i++)\n            target = max(target,bfs(adj2,i,k-1,m));\n        \n        for(int i=0;i<=n;i++)\n        {\n            ans[i] = (target + bfs(adj1,i,k,n));\n        }\n        \n        return ans;\n    }\n};\n```
['C++']