Easy Cpp
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# 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:\nmap<int,vector<int>> t1,t2;\n\nint dfs(int node,int par,int d ,int k , map<int,vector<int>>& t){\nif(d == k) return 0;\nint a = 0;\n    for(auto i : t[node]){\n        if(i!=par){\n          a +=  dfs(i,node,d+1,k,t)+1;\n        }\n    }\n\n    return a ;\n}\n\n\nvector<int> maxTargetNodes(vector<vector<int>>& e1, vector<vector<int>>& e2, int k) {\n        vector<int> ans;\n        for(auto i : e1){\n            t1[i[0]].push_back(i[1]);\n            t1[i[1]].push_back(i[0]);\n        }\n\n        for(auto i : e2){\n            t2[i[0]].push_back(i[1]);\n            t2[i[1]].push_back(i[0]);\n        }\n        ans.resize(e1.size()+1);\n        // memset(ans,0,sizeof(ans));\n        int a = 0;\n\n        if(k!= 0){\n        for(int i = 0;i<e2.size()+1;i++){\n            int x = dfs(i,-1,0,k-1,t2)+1 ; \n\n            cout<<i<<" a val"<<x<<endl; \n            a = max(a,x) ;\n        }\n        cout<<a<<endl;\n        }\n     \n\n\n\n        for(int i =0 ;i<ans.size();i++){\n            \n           int x = dfs(i,-1,0,k,t1)+1;\n    // cout<<x<<endl;\n            ans[i] = x+a ;\n\n        }\n        \n\n    return ans;\n        \n    }\n};\n```
['C++']