DFS From Each Node
For the first tree, we run DFS from each node for up to k edges.\n\nFor the second tree, we run DFS from each node for up to k - 1 edges. We track the maximum o
For the first tree, we run DFS from each node for up to `k` edges.\n\nFor the second tree, we run DFS from each node for up to `k - 1` edges. We track the maximum of targets in `max2`.\n\nWe need to add `max2` to the final result for each node in the first tree.\n\n**C++**\n```cpp\nint dfs(int i, int p, vector<vector<int>> &al, int k) {\n    if (k <= 0)\n        return k == 0;\n    int res = 1;\n    for (int j : al[i])\n        if (j != p)\n            res += dfs(j, i, al, k - 1);\n    return res;\n}\nvector<vector<int>> adjacencyList(vector<vector<int>>& edges) {\n    vector<vector<int>> al(edges.size() + 1);\n    for (auto &e: edges) {\n        al[e[0]].push_back(e[1]);\n        al[e[1]].push_back(e[0]);            \n    }        \n    return al;\n}\nvector<int> maxTargetNodes(vector<vector<int>>& e1, vector<vector<int>>& e2, int k) {\n    int m = e1.size() + 1, n = e2.size() + 1, max2 = 0;\n    auto al1 = adjacencyList(e1), al2 = adjacencyList(e2);\n    vector<int> res(m);\n    for (int i = 0; i < n; ++i)\n        max2 = max(max2, dfs(i, -1, al2, k - 1));\n    for (int i = 0; i < m; ++i)\n        res[i] = max2 + dfs(i, -1, al1, k);        \n    return res;\n}\n```
[]