Graph Traversal for each node
\n\n# Complexity\n- Time complexity:O(n^2+m^2)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(n+m)\n Add your space complexity here, e.g. O
\n\n# Complexity\n- Time complexity:O(n^2+m^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n+m)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n     void dfs(int node,int par,unordered_map<int,vector<int>> &adj,int k,int level,int &ans){\n\n        if(level<=k)\n        ans++;\n\n        for(auto i:adj[node]){\n            if(i!=par)\n            dfs(i,node,adj,k,level+1,ans);\n        }\n     }\n    vector<int> maxTargetNodes(vector<vector<int>>& edges1, vector<vector<int>>& edges2, int k) {\n       unordered_map<int,vector<int>> adj1,adj2;\n\n       for(auto e:edges1){\n        adj1[e[0]].push_back(e[1]);\n        adj1[e[1]].push_back(e[0]);\n       }\n\n       for(auto e:edges2){\n        adj2[e[0]].push_back(e[1]);\n        adj2[e[1]].push_back(e[0]);\n       }\n\n        int m=edges1.size()+1;\n        int n=edges2.size()+1;\n\n\n        vector<int> v(m,0);\n\n        for(int i=0;i<m;i++){\n            int ans=0;\n            dfs(i,-1,adj1,k,0,ans);\n            v[i]=ans;\n        }\n        int maxi=0;\n        for(int i=0;i<n;i++){\n            int ans=0;\n            dfs(i,-1,adj2,k-1,0,ans);\n            maxi=max(ans,maxi);\n        }\n\n        \n\n        for(int i=0;i<m;i++){\n            v[i]+=maxi;\n        }\n\n        return v;\n\n\n    }\n};\n```
['Tree', 'Depth-First Search', 'Breadth-First Search', 'C++']