publicclassMain2 { publicstaticvoidmain(String[] args) { Scannerscanner=newScanner(System.in); intM= scanner.nextInt(); intN= scanner.nextInt(); intm= M; intn= N; int area[][] = newint[m][n]; while (m-->0){ while (n-->0){ area[m][n] = scanner.nextInt(); } n = N; } m= M; n = N; int t; while (m-->0){ while (n-->0){ t = scanner.nextInt(); area[m][n] = area[m][n]==t?1:0; } n = N; } intans=0; for (inti=0;i!=M;++i){ for (intj=0;j!=N;++j){ ans = Math.max(ans,dfs(area,i,j)); } } System.out.println(ans); } publicstaticintdfs(int [][]area,int cur_i,int cur_j){ if (cur_i<0||cur_j<0||cur_i==area.length||cur_j==area[0].length||area[cur_i][cur_j]!=1){ return0; } area[cur_i][cur_j] = 0; int []di = {0,0,1,-1}; int dj[] = {1,-1,0,0}; intans=1; for (intindex=0;index!=4;++index){ intnext_i= cur_i+di[index],next_j = cur_j+dj[index]; ans+=dfs(area,next_i,next_j); } return ans; }