[c++] Begginner friendly if you know Union Find algo
Main idea:-\n1) join all computers as question says.\n2) Now find total number of different components // (finding parent will be enough count it.)\n3) At last 
**Main idea:-**\n1) join all computers as question says.\n2) Now find total number of different components // (finding parent will be enough count it.)\n3) At last we require only  count(different component) - 1 cables to  connect different computers;\n   \nand in code we are doing the same->\n```\nclass Solution {\npublic:\n    \n    vector<int> parent;\n    vector<int> rank;\n    \n    int findPar(int u){\n        if(parent[u]==u) return u;\n        return parent[u]=findPar(parent[u]); //path compresssion, storing the computed value;\n    }\n    void unionn(int u, int v){\n        u= findPar(u);\n        v= findPar(v);\n        //smaller rank guy gets attached to the higher rank guy\n        //only same rank -> then increase any one\'s rank\n        \n        if(rank[u]<rank[v]) \n            parent[u]=v; //smaller rank is u and its parent is v\n        else if(rank[v]<rank[u])\n            parent[v]=u;  //smaller rank is v and its parent is u\n        else {\n            parent[v]=u;\n            rank[v]++;\n        }\n    }\n    \n    int makeConnected(int n, vector<vector<int>>& conn) {\n        if(conn.size()< n-1) return -1; // to combine n computer we require n-1 wires but here it\'s not the case\n        \n        //filling parent and rank array;\n        for(int i=0;i<n;i++)\n            parent.push_back(i), rank.push_back(0);\n        \n        //iterating to connection array and connecting them\n        for(auto &it: conn)\n            unionn(it[0], it[1]);\n        \n        //counting number of different components;\n        int differentComponents= 0;\n        for(int i=0;i<n;i++)\n            if(parent[i]==i) differentComponents++;\n        \n        //total {DifferentComponents} components are there and we need to join them in mininimum cable \n        //so best way to join them will be linearly( think ) which will require DifferentComponents-1 cables only;\n        return differentComponents-1;\n    }\n};\n```\n\n**Complexity Analysis**\n\nTime: O(m), where m is the number of connections (union operations) or (alpha*m) here alpha can be considered to be constant as we are doing path compression.\nMemory: O(n+n) = O(n) for the disjoint set.
['Union Find', 'Graph', 'C', 'C++']