Easy solution || Faster than others || Simple DFS solution for finding connected components
```\nclass Solution {\nprivate:\n    void dfs(vector> &adj, vector &visited, int src)\n    {\n        visited[src] = true;\n        for(int i : adj[src])\n     
```\nclass Solution {\nprivate:\n    void dfs(vector<vector<int>> &adj, vector<bool> &visited, int src)\n    {\n        visited[src] = true;\n        for(int i : adj[src])\n            if(!visited[i])\n                dfs(adj, visited, i);\n    }\npublic:\n    int makeConnected(int n, vector<vector<int>>& connections) {\n        \n        //we need n-1 edges atleast for n vertices is connection size is lesser means we don\'t have sufficient edges\n        if(connections.size() < n - 1)\n            return -1;\n        vector<vector<int>> adj(n);\n        for(auto v : connections)\n        {\n            adj[v[0]].push_back(v[1]);\n            adj[v[1]].push_back(v[0]);\n        }\n        vector<bool> visited(n, false);\n        int components = 0;\n        for(int i=0; i<n; i++)\n            if(!visited[i])\n            {\n                dfs(adj, visited, i);\n                components++;\n            }\n        return components - 1;\n    }\n};
['Depth-First Search', 'C', 'C++']