Complete Intuition Explained || Easy to understand
\n\n\n\nclass Solution {\npublic:\n    void dfs(vector<vector<int>>&adj, vector<bool>&visited, int currNode)\n    { \n        visited[currNode] = true;\n       
![image](https://assets.leetcode.com/users/images/c2f42477-c6e4-45ad-8185-776b03252aeb_1679532996.0526953.png)\n![image](https://assets.leetcode.com/users/images/52f1efb2-1dd6-46c7-95f4-16d2c2e97db8_1679533004.0631475.png)\n\n```\nclass Solution {\npublic:\n    void dfs(vector<vector<int>>&adj, vector<bool>&visited, int currNode)\n    { \n        visited[currNode] = true;\n        for (int adjNode : adj[currNode])\n        {\n            if (visited[adjNode]) continue;\n            dfs(adj, visited, adjNode);\n        }\n    }\n    int makeConnected(int n, vector<vector<int>>& connections) \n    {\n        int currWireCount = connections.size();\n        int requiredWireCount = n - 1;\n        if (currWireCount < requiredWireCount) return -1;\n        //========================================================\n        vector<vector<int>>adj(n);\n        for (vector<int>connection : connections)\n        {\n            adj[connection[0]].push_back(connection[1]);\n            adj[connection[1]].push_back(connection[0]);\n        }\n        //==========================================================\n        vector<bool>visited(n, false);\n        int componentCount = 0;\n        for (int node = 0; node < n; node++)\n        {\n            if (visited[node]) continue;\n            dfs(adj, visited, node);\n            componentCount++;\n        }\n        //===========================================================\n        return componentCount - 1;\n    }\n};\n```
['Depth-First Search', 'Graph', 'C', 'C++']