Video Explanation Solution easy to understand | Programming with Pirai | Half Moon Coder.
\n# Code\npython3 []\nclass Solution:\n    def maxTargetNodes(self, edges1: List[List[int]], edges2: List[List[int]], k: int) -> List[int]:\n        v=set()\n  
\n# Code\n```python3 []\nclass Solution:\n    def maxTargetNodes(self, edges1: List[List[int]], edges2: List[List[int]], k: int) -> List[int]:\n        v=set()\n        adj1={}\n        adj2={}\n        n=m=0\n        for a,b in edges1:\n            if a not in adj1: adj1[a]=[]\n            if b not in adj1: adj1[b]=[]\n            adj1[a].append(b)\n            adj1[b].append(a)\n            n=max(n,a,b)\n        for x,y in edges2:\n            if x not in adj2: adj2[x]=[]\n            if y not in adj2: adj2[y]=[]\n            adj2[x].append(y)\n            adj2[y].append(x)\n            m=max(m,x,y)\n            \n        def tree2(root,k,adj):\n            if k==-1 or root in v: return 0\n            res=1\n            v.add(root)\n            for i in adj[root]:\n                res+=tree2(i,k-1,adj)\n            v.remove(root)\n            return res\n            \n        ans=0\n        for i in range(m+1):\n            ans=max(tree2(i,k-1,adj2),ans)\n        \n        res=[]\n        for i in range(n+1):\n            val=tree2(i,k,adj1)\n            # print(val)\n            res.append(val+ans)\n        return res\n```
['Depth-First Search', 'Breadth-First Search', 'Graph', 'Python3']