Count The Connected Network (C++)
Explanation\nWe need at least n - 1 cables to connect all nodes (like a tree).\nIf connections.size() < n - 1, we can directly return -1.\n\nOne trick is that, 
**Explanation**\nWe need at least n - 1 cables to connect all nodes (like a tree).\nIf connections.size() < n - 1, we can directly return -1.\n\nOne trick is that, if we have enough cables,\nwe don\'t need to worry about where we can get the cable from.\n\nWe only need to count the number of connected networks.\nTo connect two unconneccted networks, we need to set one cable.\n\nThe number of operations we need = the number of connected networks - 1\n\n\n**Complexity**\nTime O(connections)\nSpace O(n)\n\n\n```\nclass Solution {\n    int bfsOfGraph(int V, vector<int> adj[])\n    {\n        int ans=0;\n    vector<bool> vis(V, false);\n    for (int i = 0; i < V; ++i) \n    {\n        if (!vis[i]) \n        {\n            queue<int> q;\n            vis[i] = true;\n            q.push(i);\n            ans++;\n            while (!q.empty()) {\n                int g_node = q.front();\n                q.pop();\n                // bfs_traversal.push_back(g_node);\n                for (auto it : adj[g_node]) {\n                    if (!vis[it]) {\n                        vis[it] = true;\n                        q.push(it);\n                    }\n                }\n            }\n        }\n    }\n    return ans;\n}\npublic:\n    int makeConnected(int n, vector<vector<int>>& con)\n    {\n        vector<int>adj[n];\n            if(con.size()<n-1)\n               return -1;\n\t\t\t   //adjency list\n        for(int i=0;i<con.size();i++)\n        {\n                adj[con[i][1]].push_back(con[i][0]);\n                adj[con[i][0]].push_back(con[i][1]);\n\n        }\n    \n            return bfsOfGraph(n,adj)-1;\n    }\n};\n```
['Breadth-First Search', 'Graph', 'C++']