c++ solution || easy to understand || dfs traversal || with explanation
The main idea is here to get the number of connected component in graph ;\nNumber of edge in graph = connections.size() , so we can make connection of connectio
The main idea is here to get the number of connected component in graph ;\nNumber of edge in graph = connections.size() , so we can make connection of connections.size()+1 computer connected.. //condition for returning -1 \n\nif we want to connection among all computer so number of connected component must be 1.. \nnumber of conneted component -1 will be required cabel to make one connection\n\n```\nclass Solution {\npublic:\n    void dfs_traversal(vector<vector<int>>& graph , vector<bool>& visited , int start){\n        visited[start]=true;\n        for(auto it : graph[start]){\n            if(!visited[it]){\n                dfs_traversal(graph , visited , it );\n            }\n        }\n    }\n    \n    int makeConnected(int n, vector<vector<int>>& connections) {\n        if(n>connections.size()+1)\n            return -1;\n        \n        vector<vector<int>> graph(n);\n        for(auto con : connections){\n            graph[con[0]].push_back(con[1]);\n            graph[con[1]].push_back(con[0]);\n        }\n        vector<bool> visited(n ,false);\n        int component=0;\n        for(int i=0;i<n;i++){\n            if(!visited[i]){\n                component++;\n                dfs_traversal(graph , visited , i);\n            }\n        }\n        return component-1;\n    }\n};\n```
['Depth-First Search', 'C']