[C++] Simple union find solution.
\nclass Solution {\npublic:\n    \n    int find(vector<int> &parent, int v){\n        int root = v;\n        while(root != parent[root]){\n            root = pa
```\nclass Solution {\npublic:\n    \n    int find(vector<int> &parent, int v){\n        int root = v;\n        while(root != parent[root]){\n            root = parent[root];\n        }\n        \n        return root;\n    }\n    \n    void unify(vector<int> &parent, int u, int v){\n        int root_u = find(parent, u);\n        int root_v = find(parent, v);\n        \n        if(root_u == root_v){\n            return;\n        }\n        parent[root_u] = root_v;\n    }\n    \n    int makeConnected(int n, vector<vector<int>>& connections) {\n        int i, j, used = 0, redundent = 0, total = 0;\n        vector<int> parent(n);\n        for(i = 0; i < n; i++){\n            parent[i] = i;\n        }\n        \n        for(i = 0; i < connections.size(); i++){\n            if(find(parent, connections[i][0]) == find(parent, connections[i][1])){\n                redundent++;\n            }else{\n                used++;\n                unify(parent, connections[i][0], connections[i][1]);\n            }\n        }\n        \n        for(i = 0; i < n; i++){\n            total += parent[i] == i? 1 : 0;\n        }\n        \n        // cout << used << " " << redundent << " " << total << endl;\n        return total - 1 <= redundent ? total-1 : -1;\n    }\n};\n```
['Union Find', 'C']