Python3 solution | BFS | Brute force
IntuitionBrute force.ApproachIterate over all the nodes from tree2 and for each one get the number of nodes which are at a distance <= k and get the maximum sco
# Intuition
Brute force.

# Approach
Iterate over all the nodes from tree2 and for each one get the number of nodes which are at a distance <= k and get the maximum score. Iterate over tree1 and for each node get the number of nodes which are at a distance <= k+1 and add to the maximum score from tree2.
# Complexity
- Time complexity:
$$O(n*n+m*m)$$

- Space complexity:
$$O(n+m)$$

# Code
```python3 []
class Solution:
    def maxTargetNodes(self, edges1: List[List[int]], edges2: List[List[int]], k: int) -> List[int]:
        tree1, tree2 = defaultdict(lambda: []), defaultdict(lambda: [])
        ans = []
        for i in range(len(edges1)):
            tree1[edges1[i][0]].append(edges1[i][1])
            tree1[edges1[i][1]].append(edges1[i][0])
        for i in range(len(edges2)):
            tree2[edges2[i][0]].append(edges2[i][1])
            tree2[edges2[i][1]].append(edges2[i][0])
        
        max_score_tree2 = 0
        for i, element in enumerate(tree2):
            max_score_tree2 = max(max_score_tree2, self.bfs(element, tree2, k))
        
        for i in range(len(tree1)):
            current_score_tree1 = self.bfs(i, tree1, k+1) + max_score_tree2
            ans.append(current_score_tree1)
        return ans


    def bfs(self, start_node, graph, k):
        count_nodes = 0
        queue = [start_node]
        visited = set()
        level = {start_node: 1}
        visited.add(start_node)

        while queue:
            current_node = queue.pop(0)
            if level[current_node] <= k:
                count_nodes += 1
                for neigh_node in graph[current_node]:
                    if neigh_node not in visited:
                        level[neigh_node] = level[current_node] + 1
                        visited.add(neigh_node)
                        queue.append(neigh_node)
            else:
                break
        return count_nodes
        

```
['Breadth-First Search', 'Python3']