c++ solution using dfs
\nclass Solution {\npublic:\n    // step 1. create graph give edges \n    vector<vector<int>>createGraph(vector<vector<int>>&edges){\n        int n=edges.size()
```\nclass Solution {\npublic:\n    // step 1. create graph give edges \n    vector<vector<int>>createGraph(vector<vector<int>>&edges){\n        int n=edges.size();\n        vector<vector<int>>graph(n+1);\n        for(auto &edge:edges){\n            graph[edge[0]].push_back(edge[1]);\n            graph[edge[1]].push_back(edge[0]);\n        }\n        return graph;\n    }\n    int countNodes(vector<vector<int>>&edges,int node,int k,int p=-1){\n        if(k<0){\n            return 0;\n        }\n        int count=1;\n        for(auto &child:edges[node]){\n            if(p!=child){\n                count+=countNodes(edges, child, k-1, node);\n            }\n        }\n        return count;\n    }\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        auto graph1=createGraph(edges1);\n        auto graph2=createGraph(edges2);\n        int maxNodeCount=0;\n        for(int i=0;i<=m;i++){\n            maxNodeCount=max(maxNodeCount,countNodes(graph2,i,k-1));\n        }\n        vector<int>ans;\n        for(int i=0;i<=n;i++){\n            int value=maxNodeCount+countNodes(graph1,i,k);\n            ans.push_back(value);\n        }\n        return ans;\n    }\n};\n```
['Depth-First Search', 'C', 'C++']