BFS
\n# Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \nO(n(E1+V1)) + O(m(E2+V2))\n- E1 = n \n- E2 = m\n* O(n^2 + v1) + O(m^2 + v2)  == 
\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n*(E1+V1)) + O(m*(E2+V2))\n- E1 = n \n- E2 = m\n* O(n^2 + v1) + O(m^2 + v2)  == O(n^2 + m^2) == O(n^2)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(v)\n---\n# Code\n```cpp []\nclass Solution {\npublic:\nvector<int>adj1[1000];\nvector<int>adj2[1000];\nint ans[1000], vis[1000];\nint mx=0;\nvoid BFS(int u, int k, bool f){\n    queue<pair<int, int>>q;\n    q.push({u, 0});\n    while(q.size()){\n        auto it=q.front();\n        int x=it.first, y=it.second;\n        q.pop();\n        vis[x]=1;\n        \n        if(f==1 && y<=k) {\n            ans[u]++;\n            for(auto v: adj1[x]){\n                if(vis[v]==1) continue;\n                q.push({v, y+1});\n            }\n        }\n        else if(f == 0 && y <= k-1) {\n            mx= mx+1;\n            for(auto v: adj2[x]){\n                if(vis[v]==1) continue;\n                q.push({v, y+1});\n            }\n        }\n    }\n}\n\n    vector<int> maxTargetNodes(vector<vector<int>>& edges1, vector<vector<int>>& edges2, int k) {\n        int n = edges1.size(), m = edges2.size();\n        for(auto it: edges1){\n            adj1[it[0]].push_back(it[1]);\n            adj1[it[1]].push_back(it[0]);\n        }\n        for(auto it: edges2){\n            adj2[it[0]].push_back(it[1]);\n            adj2[it[1]].push_back(it[0]);\n        }\n        //////////////////////////////////\n        \n        for(int i=0; i<=n; i++){\n            for(int i=0; i<=n; i++)  vis[i]=0;\n            BFS(i, k, 1);\n        }\n\n        int mxCount=0;\n        for(int i=0; i<=m; i++){\n            for(int i=0; i<=m; i++)  vis[i]=0;\n            BFS(i, k, 0);\n            mxCount = max(mxCount, mx);\n            mx=0;\n        }\n         vector<int>res(n+1);\n        for(int i=0; i<=n; i++) res[i] = ans[i]+mxCount;\n        return res;\n    }\n};\n```
['Tree', 'Depth-First Search', 'Breadth-First Search', 'C++']