SHORT & SWEET || EASY TO UNDERSTAND || C++ || DFS
\nclass Solution {\npublic:\n    void solve(int s,vector<bool> &v,vector<vector<int>> &g){\n        if(v[s])return;\n        v[s] = true;\n        for(auto &i: 
````\nclass Solution {\npublic:\n    void solve(int s,vector<bool> &v,vector<vector<int>> &g){\n        if(v[s])return;\n        v[s] = true;\n        for(auto &i: g[s]){\n            solve(i,v,g);\n        }\n    }\n    int makeConnected(int n, vector<vector<int>>& v) {\n        if(v.size()<n-1)return -1;\n        vector<vector<int>> g(n);\n        for(auto &i: v){\n            g[i[0]].push_back(i[1]);\n            g[i[1]].push_back(i[0]);\n        }\n        vector<bool> vis(n,false);\n        int ans = -1;\n        for(int i = 0; i < n; i++){\n            if(!vis[i]){\n                solve(i,vis,g);\n                ans++;\n            }\n        }\n        return ans;\n    }\n};\n````
['Depth-First Search', 'C', 'C++']