DFS || Easy To Understand || C++
Code
# Code
```cpp []
class Solution 
{
public:
    int countNodes(int node, int distance, int d, vector<int> &vis, vector<int> adj[])
    {
        if(d>distance) return 0;
        vis[node]=1;
        int cnt=1;
        for(auto it: adj[node])
        {
            if(!vis[it]) cnt+=countNodes(it,distance, d+1,vis,adj);
        }
        return cnt;
    }
    vector<int> maxTargetNodes(vector<vector<int>>& edges1, vector<vector<int>>& edges2, int k) 
    {
        int n=edges1.size(), m=edges2.size();
        vector<int> adj1[n+1], adj2[m+1];
        for(auto it: edges1) 
        {
            adj1[it[0]].push_back(it[1]);
            adj1[it[1]].push_back(it[0]);
        }
        for(auto it: edges2)
        {
            adj2[it[0]].push_back(it[1]);
            adj2[it[1]].push_back(it[0]);
        }
        vector<int> ans(n+1);
        for(int x=0; x<=n; x++)
        {
            vector<int> vis(n+1,0);
            ans[x]=countNodes(x,k,0,vis,adj1);
        }
        int mx=0;
        for(int x=0; x<=m; x++)
        {
            vector<int> vis(m+1,0);
            mx=max(mx,countNodes(x,k-1,0,vis,adj2));
        }
        for(int x=0; x<=n; x++) ans[x]+=mx;
        return ans;
    }
};
```
['Depth-First Search', 'C++']