Easy BFS || Clean Code || JAVA
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public static class Tree {\n        public int size;\n        public List<List<Integer>> adjList;\n\n        public Tree(final int size) {\n            this.size = size;\n        }\n\n        public static class Node {\n            public int ele, count;\n\n            public Node(final int ele, final int count) {\n                this.ele = ele;\n                this.count = count;\n            }\n        }\n\n        public void construct(final int[][] edges) {\n            this.adjList = new ArrayList<>();\n\n            for (int i = 0; i < size; i++) adjList.add(new ArrayList<>());\n\n            for (final int[] edge : edges) {\n                adjList.get(edge[0]).add(edge[1]);\n                adjList.get(edge[1]).add(edge[0]);\n            }\n        }\n\n        public int kDistBfs(final int node, final int k) {\n            final boolean[] visited = new boolean[size];\n            final Queue<Node> queue = new ArrayDeque<>();\n\n            visited[node] = true;\n            queue.add(new Node(node, 0));\n\n            int count = 0;\n\n            while(!queue.isEmpty()) {\n                final Node cur = queue.remove();\n\n                count++;\n\n                for (final int child : adjList.get(cur.ele)) {\n                    if (!visited[child] && cur.count + 1 <= k) {\n                        visited[child] = true;\n\n                        queue.add(new Node(child, cur.count + 1));\n                    }\n                }\n            }\n\n            return count;\n        }\n\n        public int[] kNearestCount(final int k) {\n            final int[] kNearest = new int[size];\n\n            for (int i = 0; i < size; i++) {\n                kNearest[i] = kDistBfs(i, k);\n            }\n\n            return kNearest;\n        }\n    }\n\n    public int[] maxTargetNodes(int[][] edges1, int[][] edges2, int k) {\n        final int n = edges1.length + 1;\n        final int m = edges2.length + 1;\n\n        final Tree t1 = new Tree(n);\n        final Tree t2 = new Tree(m);\n\n        t1.construct(edges1);\n        t2.construct(edges2);\n\n        final int[] t1KNearest = t1.kNearestCount(k);\n        final int[] t2KNearest = t2.kNearestCount(k - 1);\n\n        if (k == 0) return t1KNearest;\n\n        int max = 0;\n\n        for (int i = 0; i < m; i++) {\n            max = Integer.max(max, t2KNearest[i]);\n        }\n\n        for (int i = 0; i < n; i++) {\n            t1KNearest[i] += max;\n        }\n\n        return t1KNearest;\n    }\n}\n```
['Java']