Number of Operations to Make Network Connected - DFS
void dfs(int src, ArrayList> adj, boolean[]visit){\n        visit[src]=true;\n        \n        for(int i:adj.get(src)){\n            if(!visit[i]){\n          
void dfs(int src, ArrayList<ArrayList<Integer>> adj, boolean[]visit){\n        visit[src]=true;\n        \n        for(int i:adj.get(src)){\n            if(!visit[i]){\n                dfs(i, adj, visit);\n            }\n        }\n    }\n    \n    public int makeConnected(int n, int[][] connections) {\n        ArrayList<ArrayList<Integer>> adj = new ArrayList<>();\n        \n        int m = connections.length;\n        if(m<n-1){\n            return -1;\n        }\n        \n        for(int i=0; i<n; i++){\n            adj.add(new ArrayList<>());\n        }\n        \n        for(int[] i:connections){\n            adj.get(i[0]).add(i[1]);\n            adj.get(i[1]).add(i[0]);\n        }\n        \n        boolean[]visit = new boolean[n];\n        int cou=0;\n        \n        for(int i=0; i<n; i++){\n            if(!visit[i]){\n                cou++;\n                dfs(i, adj, visit);\n            }\n        }\n        return cou-1;\n    }
['Depth-First Search', 'Graph', 'Java']