C++ Easy approach
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 {\n     vector<vector<int>>populateGraph(vector<vector<int>>& edges){\n        int n = edges.size();\n        vector<vector<int>>graph(n+1);\n        for(auto& edge:edges){\n            graph[edge[1]].push_back(edge[0]);\n            graph[edge[0]].push_back(edge[1]);\n        }\n        return graph;\n     }\n     int numOfNodeAtDistHelper(vector<vector<int>>&graph,int node,int dist){\n        int n = graph.size();\n        queue<pair<int,int>>q;\n        vector<int>visited(n,0);\n        q.push({node,0});\n        int cnt = 0;\n        while(q.size()){\n            auto curr = q.front();\n            q.pop();\n            if(visited[curr.first]) continue;\n            visited[curr.first]++;\n            cnt++;\n            if(curr.second == dist)continue;\n            for(auto nbr:graph[curr.first]){\n                if(visited[nbr])continue;\n                q.push({nbr,curr.second+1});\n            }\n        }\n        return cnt;\n     }\n     unordered_map<int,int>numOfNodeAtDist(vector<vector<int>>&graph,int dist){\n        int n= graph.size();\n        unordered_map<int,int>nodeCountMap;\n        // will do bfs for each node and return\n        for(int i=0;i<n;i++){\n            int cnt = numOfNodeAtDistHelper(graph,i,dist);\n            cout<<cnt<<",";\n            nodeCountMap[i]= cnt;\n        }\n        return nodeCountMap;\n     }\n\npublic:\n    vector<int> maxTargetNodes(vector<vector<int>>& edges1, vector<vector<int>>& edges2, int k) {\n        int n = edges1.size();\n        int m = edges2.size();\n        vector<int>ans(n+1,1);\n        if(k==0)return ans; // only that node is target to itself\n        vector<vector<int>>graph1 = populateGraph(edges1);\n        vector<vector<int>>graph2 = populateGraph(edges2);\n        unordered_map<int,int>numOfNodeAtDist1 = numOfNodeAtDist(graph1,k);\n        unordered_map<int,int>numOfNodeAtDist2 = numOfNodeAtDist(graph2,k-1);\n        int maxi = 0;\n        for(auto val :numOfNodeAtDist2){\n            maxi = max(maxi,val.second);\n        }\n        for(int i=0; i<=n; i++){\n            ans[i]= numOfNodeAtDist1[i]+maxi;\n        }\n        return ans;\n        \n    }\n};\n```
['C++']