simple dfs c++  solution
min no of edges to connect n node is n-1 so connecting wire must be greater or equal to n-1\nthen , Simply just find   (no. of connected component -1)  using df
min no of edges to connect n node is n-1 so connecting wire must be greater or equal to n-1\nthen , Simply just find   (no. of connected component -1)  using dfs method\n\n\n```\nclass Solution {\npublic:\n    \n    void dfs(int u,vector<vector<int>> &v, vector<bool> & vis){\n        \n        if(vis[u]) return;\n        \n        vis[u]=true;\n        \n        for(auto it: v[u]){\n            \n            dfs(it,v,vis);\n        }\n        \n    }\n    \n    int makeConnected(int n, vector<vector<int>>& connections) {\n        \n        int len=connections.size();\n        \n        if(len<n-1) return -1;\n        \n        \n        vector<vector<int>> v(n);\n        \n        int x,y;\n        \n        for(int i=0;i<len;i++){\n            x=connections[i][0];\n            y=connections[i][1];\n            \n            v[x].push_back(y);\n            v[y].push_back(x);\n            \n        }\n        \n        int cnt=0;\n        \n        vector<bool> vis(n,false);\n        \n        for(int i=0;i<n;i++){\n            \n            if(!vis[i]) {\n                \n                cnt++;\n                \n                dfs(i,v,vis);\n            }\n        }\n        \n        return cnt-1;\n        \n        \n        \n        \n        \n    }\n};\n```
[]