C++ || BFS
Make adjacency list of the given graph and traverse se, whenever you find a disconnected component count 1.\n\n\nclass Solution {\npublic:\n    int makeConnecte
Make adjacency list of the given graph and traverse se, whenever you find a disconnected component count 1.\n\n```\nclass Solution {\npublic:\n    int makeConnected(int n, vector<vector<int>>& c) {\n        int edges = c.size();;\n        \n        if( edges < n - 1 ){\n            return -1;\n        }\n        \n        vector<int> adj[n];\n        vector<int> vis(n, 0);\n        \n        for( int i=0; i < c.size(); i++ ) {\n            adj[ c[i][0] ].push_back( c[i][1] );\n            adj[ c[i][1] ].push_back( c[i][0] );\n        }\n        queue<int> q;\n        int count = 0;\n        \n        for(int i = 0; i<n; i++) {\n            if( !vis[i] ) {\n               count++;\n               vis[i] = 1;\n                q.push(i);\n               while(!q.empty()){  \n                int node = q.front();\n                q.pop();\n                for(auto x : adj[node]) {\n                    if( !vis[x] ) {\n                        q.push(x);\n                        vis[x] = 1;\n                    }\n                } \n             }\n           }\n        }\n        count--;\n        return count;        \n    }\n};\n```
['Breadth-First Search', 'Queue', 'C', 'Iterator']