Simple DFS Based Solution With proper comments
Intuition\nDFS to find sum of nodes upto\n 1. k-1th level in tree 2\n 2. kth level in tree 1\n\n \nSum above 2\n\n# Complexity\n- Time complexity: O(n) \n Add y
# Intuition\nDFS to find sum of nodes upto\n 1. k-1th level in tree 2\n 2. kth level in tree 1\n\n \nSum above 2\n\n# Complexity\n- Time complexity: $$O(n)$$ \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$ \n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n\n    //simple dfs to get sum of nodes uptil level k\n    int compute_at_k(int node,int level,int k,unordered_map<int,vector<int>>&graph,unordered_map<int,int>&visited){\n\n        if(level>k)\n            return 0;\n        if(level==k)\n            return 1;\n        \n        int ans = 1;\n        visited[node] = 1;\n        for(auto x:graph[node]){\n            if(!visited[x]){\n                visited[x] = 1;\n                ans+=compute_at_k(x,level+1,k,graph,visited);\n            }\n        }\n        return ans;\n    }\n    vector<int> maxTargetNodes(vector<vector<int>>& edges1, vector<vector<int>>& edges2, int k) {\n        int n = edges1.size(),m=edges2.size(),max_pot=1;\n        unordered_map<int,vector<int>>graph1,graph2;\n        unordered_map<int,int>visited;\n        vector<int>ans;\n\n        //constructing graphs here\n        for(auto x:edges2){\n            graph2[x[0]].push_back(x[1]);\n            graph2[x[1]].push_back(x[0]);\n        }\n        for(auto x:edges1){\n            graph1[x[0]].push_back(x[1]);\n            graph1[x[1]].push_back(x[0]);\n        }\n\n\n        //finding max_potential i.e. max nodes at k-1 level in graph2\n        if(k!=0){\n            for(int i=0;i<=m;i++){\n                visited.clear();\n                max_pot = max(max_pot,compute_at_k(i,0,k-1,graph2,visited));\n            }\n        } else{\n            max_pot = 0;\n        }\n\n        cout<<"Max_Potential :"<<max_pot<<endl; \n\n        for(int i=0;i<=n;i++){\n            visited.clear();\n            int nodes_at_k = compute_at_k(i,0,k,graph1,visited);\n            ans.push_back(max_pot+nodes_at_k);\n        }\n\n        return ans; \n    }\n};\n```
['C++']