DFS || Beats 100% ||  Trees
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\nint bfs(int i , vector<vector<int>>&adj, int k,int par=-1)\n{\n\n    if(k<0)\n        return 0;\n    if(k==0)\n        return 1;\n    int res=1;\n    for(auto P :adj[i])\n        {\n            if(P==par)\n                continue;\n            // if it come s to parent //loop exit\n            res+=bfs(P,adj,k-1,i);\n        }\n    return res;\n}\n    vector<int> maxTargetNodes(vector<vector<int>>& edges1, vector<vector<int>>& edges2, int k) {\n\n        int n=edges1.size()+1;\n        int m=edges2.size()+1;\n\n      vector<vector<int>> adj1(n), adj2(m);\n\n\n        for(int i=0;i<n-1;i++)\n            {\n                int u=edges1[i][0];\n                int v=edges1[i][1];\n                adj1[u].push_back(v);\n                 adj1[v].push_back(u);\n            }\n        for(int i=0;i<m-1;i++)\n            {\n                int u=edges2[i][0];\n                int v=edges2[i][1];\n                adj2[v].push_back(u);\n                 adj2[u].push_back(v);\n            }\n\n       //  we need to add node which has  maximum  neig in 2nd tree\n\n        int maxi=0;\n        for(int i=0;i<m;i++)\n            {\n                // one connection is mae we havve k-1 edges left;\n                maxi=max(maxi,bfs(i,adj2,k-1));\n                // after traversing all node we got best maxi from trr2 , to ad to each node in tree 1\n            }\n        vector<int>ans;\n\n        for(int i=0;i<n;i++)\n            {\n                int res=0;\n                // we have k edges left , we havent used any\n                res+=bfs(i,adj1,k);\n                res+=maxi;\n                ans.push_back(res);\n            }\n        return ans;\n    }\n};\n```
['C++']