Try once more using my Hints | Easy Java solution using DFS
Hints\n- Use DFS or BFSa\n- check if number of edges is less than (n-1) so we can\'t connect each node return -1;\n- If number of edges are sufficent than just 
# Hints\n- Use DFS or BFSa\n- check if number of edges is less than (n-1) so we can\'t connect each node return -1;\n- If number of edges are sufficent than just count number of disconnected sub grapes and return count - 1, because that much operations are needed.\n\n# Complexity\n- Time complexity: $$O(n + E)$$ where n are number of nodes and E is number edges\n\n- Space complexity: $$O(n + E)$$ in storing the graps in adjacency list\n    - where n are number of nodes and E is number of edges \n\n# Code\n```\nclass Solution {\n    public int makeConnected(int n, int[][] connections) {\n        int m = connections.length;\n        if(m < n-1) return -1;\n        ArrayList<ArrayList<Integer>> ls = new ArrayList<>();\n        for(int i = 0; i<n; i++) ls.add(new ArrayList<>());\n        for(int a[] : connections){\n            ls.get(a[0]).add(a[1]);\n            ls.get(a[1]).add(a[0]);\n        }\n        int countConnected = 0;\n        boolean vis[] = new boolean[n];\n        for(int i = 0; i<n; i++){\n            if(!vis[i]){\n                countConnected++;\n                dfs(ls, i, vis);\n            }\n        }\n        return countConnected-1;\n    }\n    private void dfs(ArrayList<ArrayList<Integer>> grp, int curr, boolean vis[]){\n        if(curr >= vis.length || vis[curr]) return;\n        vis[curr] = true;\n        for(int child : grp.get(curr)) dfs(grp, child, vis);\n    }\n}\n```
['Depth-First Search', 'Breadth-First Search', 'Union Find', 'Graph', 'Java']