classSolution{publicvoidtintage(int fro,int[][] isConnected,int[] vis){for(int i =0; i < isConnected.length; i ++){if(isConnected[fro][i]==1&& vis[i]==0){
vis[i]= vis[fro];tintage(i, isConnected, vis);}}}publicintfindCircleNum(int[][] isConnected){int[] vis =newint[isConnected.length];int ans =0;for(int i =0; i < isConnected.length; i ++){if(vis[i]==0) vis[i]= ans +1;tintage(i, isConnected, vis);
ans = Math.max(ans, vis[i]);}return ans;}}