Simple Breath First Search
Intuition\nSIMPLE BFS  \n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time complexity:\nO(N+M+K)\n\n- Space complexity:\nO(N+
# Intuition\nSIMPLE BFS  \n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\nO(N+M+K)\n\n- Space complexity:\nO(N+M)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    //To find the no of target nodes for the given node in the graph\n    int find_target(vector<vector<int>> &adj1,int n,int k,int start)\n    {\n        queue<int> q;\n        q.push(start);\n        int s,node,ans=0;\n        vector<bool> visted(n+1,false);\n        for(int i=0;i<=k;i++)\n        {\n            s=q.size();\n            ans+=s;\n            if(s==0)\n            break;\n            for(int j=0;j<s;j++)\n            {\n                node=q.front();\n                visted[node]=true;\n                q.pop();\n                for(auto l:adj1[node])\n                {\n                    if(visted[l]!=true)\n                    q.push(l);\n                }\n            }\n        }\n        return ans;\n    }\n    vector<int> maxTargetNodes(vector<vector<int>>& edges1,\n    vector<vector<int>>& edges2, int k) {\n        int n=edges1.size();\n        int m=edges2.size();\n        vector<int> tree1(n+1);\n        vector<int> tree2(m+1);\n        vector<vector<int>> adj1(n+1);\n        vector<vector<int>> adj2(m+1);\n        for(auto i:edges1)\n        {\n            adj1[i[0]].push_back(i[1]);\n            adj1[i[1]].push_back(i[0]);\n        }\n        for(auto i:edges2)\n        {\n            adj2[i[0]].push_back(i[1]);\n            adj2[i[1]].push_back(i[0]);\n        }\n        for(int i=0;i<=n;i++)\n        {\n            tree1[i]=find_target(adj1,n,k,i);\n        }\n        for(int i=0;i<=m;i++)\n        {\n            tree2[i]=find_target(adj2,m,k-1,i);\n        }\n        vector<int> ans(n+1,0);\n        for(int i=0;i<=n;i++)\n        {\n            for(int j=0;j<=m;j++)\n            {\n                ans[i]=max(ans[i],tree1[i]+tree2[j]);\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']