@@ -0,0 +1,1605 @@
+package graphPrac;%0Aimport java.util.*;%0Apublic class Main %7B%0A    public static final int%5B%5D dx = %7B0, 0, 1, -1%7D;%0A    public static final int%5B%5D dy = %7B1, -1, 0, 0%7D;%0A    public static void dfs(int%5B%5D%5B%5D a, int%5B%5D%5B%5D group, int x, int y, int cnt, int n) %7B%0A        group%5Bx%5D%5By%5D = cnt;%0A        for (int k=0; k%3C4; k++) %7B%0A            int nx = x+dx%5Bk%5D;%0A            int ny = y+dy%5Bk%5D;%0A            if (0 %3C= nx && nx %3C n && 0 %3C= ny && ny %3C n) %7B%0A                if (a%5Bnx%5D%5Bny%5D == 1 && group%5Bnx%5D%5Bny%5D == 0) %7B%0A                    dfs(a, group, nx, ny, cnt, n);%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A    public static void main(String args%5B%5D) %7B%0A        Scanner sc = new Scanner(System.in);%0A        int n = sc.nextInt();%0A        sc.nextLine();%0A        int%5B%5D%5B%5D a = new int%5Bn%5D%5Bn%5D;%0A        for (int i=0; i%3Cn; i++) %7B%0A            String s = sc.nextLine();%0A            for (int j=0; j%3Cn; j++) %7B%0A                a%5Bi%5D%5Bj%5D = s.charAt(j) - '0';%0A            %7D%0A        %7D%0A        int cnt = 0;%0A        int%5B%5D%5B%5D group = new int%5Bn%5D%5Bn%5D;%0A        for (int i=0; i%3Cn; i++) %7B%0A            for (int j=0; j%3Cn; j++) %7B%0A                if (a%5Bi%5D%5Bj%5D == 1 && group%5Bi%5D%5Bj%5D == 0) %7B%0A                    dfs(a, group, i, j, ++cnt, n);%0A                %7D%0A            %7D%0A        %7D%0A        int%5B%5D ans = new int%5Bcnt%5D;%0A        for (int i=0; i%3Cn; i++) %7B%0A            for (int j=0; j%3Cn; j++) %7B%0A                if (group%5Bi%5D%5Bj%5D != 0) %7B%0A                    ans%5Bgroup%5Bi%5D%5Bj%5D-1%5D+=1;%0A                %7D%0A            %7D%0A        %7D%0A        Arrays.sort(ans);%0A        System.out.println(cnt);%0A        for (int i=0; i%3Ccnt; i++) %7B%0A            System.out.println(ans%5Bi%5D);%0A        %7D%0A    %7D%0A%7D%0A%0A

solve 2776