import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner scanner=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); String[] hw=scanner.nextLine().split(" "); int h=Integer.parseInt(hw[0]); int w=Integer.parseInt(hw[1]); boolean[][] a=new boolean[h][w]; int cnt=0; for(int i=0; ipar[y]) { int tmp=x; x=y; y=tmp; } par[x]+=par[y]; par[y]=x; return true; } public boolean same(int x, int y) { return find(x)==find(y); } }