[Python3] brute-force
Intuition\nEssentially, this is a brute-force approach. For the two trees, we calculate the target nodes. For tree 1, we run DFS on each node to count its targe
**Intuition**\nEssentially, this is a brute-force approach. For the two trees, we calculate the target nodes. For tree 1, we run DFS on each node to count its target nodes of `k`. For tree 2, we do similar but count target nodes of `k-1`. This is to account for the cost of the added edge. For tree 2, we want the largest count of target nodes and apply it to all nodes of tree 1. \n\n**Analysis**\nTime complexity `O(N^2 + M^2)`\nSpace complexity `O(N + M)`\n\n**Implementation**\n```\nclass Solution:\n    def maxTargetNodes(self, edges1: List[List[int]], edges2: List[List[int]], k: int) -> List[int]:\n        \n        def fn(edges, k): \n            n = len(edges)+1\n            tree = [[] for _ in range(n)]\n            for u, v in edges: \n                tree[u].append(v)\n                tree[v].append(u)\n            ans = [0]*n\n            for x in range(n): \n                stack = [(x, -1, 0)]\n                while stack: \n                    u, p, d = stack.pop()\n                    if d <= k: ans[x] += 1\n                    for v in tree[u]: \n                        if v != p: \n                            stack.append((v, u, d+1))\n            return ans \n        \n        most = max(fn(edges2, k-1))\n        return [x+most for x in fn(edges1, k)]\n```
['Python3']