@@ -0,0 +1,2278 @@
+// Author: Stefan Toman%0A%0Aimport java.io.*;%0Aimport java.util.*;%0Aimport java.text.*;%0Aimport java.math.*;%0Aimport java.util.regex.*;%0A%0Apublic class Stefan %7B%0A    %0A    static class Pair%3CS, T%3E %7B%0A        public S a;%0A        public T b;%0A        %0A        public Pair(S a, T b) %7B%0A            this.a = a;%0A            this.b = b;%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Scanner in = new Scanner(System.in);%0A        int n = in.nextInt();%0A        int m = in.nextInt();%0A        int grid%5B%5D%5B%5D = new int%5Bn%5D%5Bm%5D;%0A        for(int grid_i=0; grid_i %3C n; grid_i++)%7B%0A            for(int grid_j=0; grid_j %3C m; grid_j++)%7B%0A                grid%5Bgrid_i%5D%5Bgrid_j%5D = in.nextInt();%0A            %7D%0A        %7D%0A        %0A        //start solution%0A        boolean visited%5B%5D%5B%5D = new boolean%5Bn%5D%5Bm%5D;%0A        int maxRegion = 0;%0A        for(int grid_i=0; grid_i %3C n; grid_i++)%7B%0A            for(int grid_j=0; grid_j %3C m; grid_j++)%7B%0A                if(!visited%5Bgrid_i%5D%5Bgrid_j%5D && grid%5Bgrid_i%5D%5Bgrid_j%5D == 1) %7B%0A                    int region = 1;%0A                    visited%5Bgrid_i%5D%5Bgrid_j%5D = true;%0A                    Queue%3CPair%3CInteger, Integer%3E%3E q = new LinkedList%3CPair%3CInteger, Integer%3E%3E();%0A                    q.add(new Pair%3CInteger, Integer%3E(grid_i, grid_j));%0A                    while(!q.isEmpty()) %7B%0A                        Pair%3CInteger, Integer%3E p = q.poll();%0A                        for(int di = p.a == 0 ? 0 : -1; di %3C= Math.min(1, n - p.a - 1); di++) %7B%0A                            for(int dj = p.b == 0 ? 0 : -1; dj %3C= Math.min(1, m - p.b - 1); dj++) %7B%0A                                if(dj != 0 %7C%7C di != 0) %7B%0A                                    if(!visited%5Bp.a + di%5D%5Bp.b + dj%5D && grid%5Bp.a + di%5D%5Bp.b + dj%5D == 1) %7B%0A                                        region++;%0A                                        visited%5Bp.a + di%5D%5Bp.b + dj%5D = true;%0A                                        q.add(new Pair%3CInteger, Integer%3E(p.a + di, p.b + dj));%0A                                    %7D%0A                                %7D    %0A                            %7D%0A                        %7D%0A                    %7D%0A                    if(region %3E maxRegion) %7B%0A                        maxRegion = region;%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A        System.out.println(maxRegion);%0A    %7D%0A%7D%0A

add Java submissions for connectedcellinagrid