c++
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    void dfs(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            }\n        }\n    }\npublic:\n    int makeConnected(int n, vector<vector<int>>& arr) {\n        int len = arr.size();\n        if(len<n-1) return -1;\n         vector<int> adj[n];\n        for(auto v : arr)\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 ans = 0;\n        for(int i=0; i<n; i++)\n        if(!visited[i])\n        {\n            dfs(adj, visited, i);\n            ans++;\n        }\n        return ans - 1;\n    }\n};\n\n\n\n```
['C++']