Easy Java Solution using DSU || 91% faster
\nclass Solution {\n    \n    int[] parent;\n    int[] rank;\n    \n    public int findParent(int node){\n        if(node == parent[node]){\n            return 
```\nclass Solution {\n    \n    int[] parent;\n    int[] rank;\n    \n    public int findParent(int node){\n        if(node == parent[node]){\n            return node;\n        }\n        return parent[node] = findParent(parent[node]);\n    }\n    \n    public void union(int u, int v){\n        int pu = findParent(u);\n        int pv = findParent(v);\n        \n        if(pu != pv){\n            int ru = rank[pu];\n            int rv = rank[pv];\n            \n            if(ru > rv){\n                parent[pv] = pu;\n            }\n            else if(rv > ru){\n                parent[pu] = pv;\n            }\n            else{\n                parent[pu] = pv;\n                rank[pu]++;\n            }\n        }\n    }\n    \n    public int makeConnected(int n, int[][] connections) {\n        parent = new int[n];\n        rank = new int[n];\n        \n        for(int i = 0; i < n; i++){\n            parent[i] = i;\n        }\n        \n        if(connections.length < n-1){\n            return -1;\n        }\n        \n        int res = 0;\n        \n        for(int[] conn : connections){\n            int u = conn[0];\n            int v = conn[1];\n            \n            if(findParent(u) != findParent(v)){\n                union(u, v);                \n            }\n        }   \n        \n        for(int i = 0; i < n; i++){\n            if(parent[i] == i){\n                res++;\n            }\n        }\n        \n        return res-1;\n    }\n}\n```
['Graph', 'Java']