beats 100%
Intuition\nfind the indegree of both tree for every node:\nfind the max indegree of second tree: \nthen add the indegree of every node of first tree with max:\n
# Intuition\nfind the indegree of both tree for every node:\nfind the max indegree of second tree: \nthen add the indegree of every node of first tree with max:\n\n\n\n# Complexity\n- Time complexity:\nk(n+m)\n\n\n\n# Code\n```java []\nclass Solution {\n    class Pair{\n        int node;int edgecount;\n       Pair(int node,int edgecount)\n        {\n            this.node=node;\n            this.edgecount=edgecount;\n        }\n    }\n    public int[] maxTargetNodes(int[][] edges1, int[][] edges2, int k) \n    {\n        int n=edges1.length;int m=edges2.length;\n        int firsttree[]=new int[n+1];int secondtree[]=new int[m+1];\n        List<List<Integer>> adj1=new ArrayList<>();\n        List<List<Integer>> adj2=new ArrayList<>();\n        for(int i=0;i<n+1;i++)\n        {\n            adj1.add(new ArrayList<>());\n        }\n        for(int i=0;i<m+1;i++)\n        {\n            adj2.add(new ArrayList<>());\n        }\n        for(int i=0;i<n;i++)\n        {\n            adj1.get(edges1[i][0]).add(edges1[i][1]);\n            adj1.get(edges1[i][1]).add(edges1[i][0]);\n        }\n        for(int i=0;i<m;i++)\n        {\n            adj2.get(edges2[i][0]).add(edges2[i][1]);\n            adj2.get(edges2[i][1]).add(edges2[i][0]);\n        }\n        for(int i=0;i<n+1;i++)\n        {\n            Queue<Pair> queue=new LinkedList<>();\n            boolean visited[]=new boolean[n+1];\n            queue.add(new Pair(i,0));\n            firsttree[i]=bfs(queue,visited,k,adj1);\n        }\n        for(int i=0;i<m+1 && k>0;i++)\n        {\n           Queue<Pair> queue=new LinkedList<>();\n            boolean visited[]=new boolean[m+1];\n            queue.add(new Pair(i,0));\n            secondtree[i]=bfs(queue,visited,k-1,adj2); \n        }\n        int max=0;\n        for(int i:secondtree)\n        {\n            max=Math.max(max,i);\n        }\n        int [] ans=new int[n+1];\n        for(int i=0;i<=n;i++)\n        {\n            ans[i]=firsttree[i]+max;\n        }\n        return ans;\n    }\n    int bfs(Queue<Pair> q,boolean visited [],int k,List<List<Integer>> adj)\n    {\n        int count=0;\n        while(!q.isEmpty())\n        {\n            Pair p=q.poll();\n            \n            int nd=p.node;\n            int ed=p.edgecount;\n            if(visited[nd]) continue;\n            visited[nd]=true;\n            count+=1;\n            for(int neighbour:adj.get(nd))\n            {\n                if(!visited[neighbour] && ed<k)\n                {\n                    q.add(new Pair(neighbour,ed+1));\n                }\n            }\n        }\n        return count;\n    }\n}\n```
['Java']