Easy BFS Solution || C++
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n/\n1.Make Adjacency Lis
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n/*\n1.Make Adjacency List for both the given graph(make it directed)\n2.Apply BFS for each node in each graph and find how many nodes have been connected with each source node\n   2.1-> for graph1 consider for K range\n   2.2-> for graph2 consider for K-1 range (because 1 edge will be added while connecting node from graph1 to node from graph2)\n3.Prepare result for each node and take only maxCount of node in graph2\n*/\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```cpp []\nclass Solution {\npublic:\n/*\n1.Make Adjacency List for both the given graph(make it directed)\n2.Apply BFS for each node in each graph and find how many nodes have been connected with each source node\n   2.1-> for graph1 consider for K range\n   2.2-> for graph2 consider for K-1 range (because 1 edge will be added while connecting node from graph1 to node from graph2)\n3.Prepare result for each node and take only maxCount of node in graph2\n*/\n    vector<int> maxTargetNodes(vector<vector<int>>& edges1, vector<vector<int>>& edges2, int k) {\n        int m=edges1.size();\n        int n=edges2.size();\n        vector<vector<int>> adj1(m+1);\n        vector<vector<int>> adj2(n+1);\n        //make adjacency list for 1 tree with m nodes\n        for(auto arr:edges1)\n        {\n            adj1[arr[0]].push_back(arr[1]);\n            adj1[arr[1]].push_back(arr[0]);\n        }\n        //make adjacency list for 2 tree with n nodes\n        for(auto arr:edges2)\n        {\n            adj2[arr[0]].push_back(arr[1]);\n            adj2[arr[1]].push_back(arr[0]);\n        }\n        // take map to count ,how many nodes have connected with src node in a K range for 1 tree\n        // take map to count ,how many nodes have connected with src node in a K-1 range for 2 tree\n        unordered_map<int,int> m1,m2;\n        int largest=0;\n        for(int node=0;node<=m;node++)\n        {\n            queue<pair<int,int>> q;\n            vector<int> visited(m+1,-1);\n            q.push({node,0});\n            visited[node]=1;\n            m1[node]++;\n            while(q.size()!=0)\n            {\n                int n=q.front().first;\n                int h=q.front().second;\n                q.pop();\n                if(h+1>k) break;\n                for(auto itr:adj1[n])\n                {\n                    if(visited[itr]==-1)\n                    {\n                        m1[node]++;\n                        visited[itr]=1;\n                        q.push({itr,h+1});\n                    }\n                }\n            }\n        }\n        for(int node=0;node<=n;node++)\n        {\n            queue<pair<int,int>> q;\n            vector<int> visited(n+1,-1);\n            q.push({node,0});\n            visited[node]=1;\n            if(k>0) m2[node]++;\n            while(q.size()!=0)\n            {\n                int n=q.front().first;\n                int h=q.front().second;\n                q.pop();\n                if(h+1>k-1) break;\n                for(auto itr:adj2[n])\n                {\n                    if(visited[itr]==-1)\n                    {\n                        m2[node]++;\n                        visited[itr]=1;\n                        q.push({itr,h+1});\n                    }\n                }\n            }\n            //we are taking maxCount in 2 tree ,bcz it will max our result\n            largest=max(m2[node],largest);\n        }\n        //iterating for each node in tree1\n        vector<int> result(m+1);\n        for(int i=0;i<=m;i++)\n        {\n            result[i]=m1[i]+largest;\n        }\n        return result;\n    }\n};\n```
['Graph', 'C++']