EQDIV

1
0
2
1 2 2 1
5
1 1 1 2 1 3 3 2 2 2
2 1 4 2 4 1 5 1 3 1
4 5 5 2 5 3 5 5 5 4
2 5 3 4 3 5 4 3 4 4
5
1 1 1 2 1 3 3 2 2 2
2 1 3 1 4 1 5 1 4 2
4 5 5 2 5 3 5 5 5 4
2 4 1 4 3 5 4 3 4 4
0
2
1 2
0
2
1 2 2 1
0
2
1 2 1 1
0
2
1 2 1 1 2 1
0
2
1 2 1 1 2 1 2 2
0
2
1 2 1 1 2 1 2 2 2 3
0
1
0
#include 
#include
using namespace std;
int input [101][101];
bool vis[101][101];
int n,cnt,counter=1;
int dx[]= {0,0,1,-1};
int dy[]= {1,-1,0,0};
bool bfs (int i,int j) //bna5od row
{
    bool ret=false;
    if (i<1||j<1||i>n||j>n)return false;
     vis[i][j]=1;
    if (counter==n) return true;
    if (counter>n) return false;
    for (int k=0; k<4; k++)
    {
        int x=i+dx[k];
        int y=j+dy[k];
        if (input[i][j]==input[x][y]&&!vis[x][y])
        {
            counter++;
            ret= ret || bfs(x,y);
        }

    }
    return ret;
}
int main()
{
    while (cin>>n&&n)
    {
        cnt=0;
        memset(vis,0,sizeof vis);
        counter=1;
        int x,y;

        for (int i=0; i>x>>y;
                input[x][y]=cnt;
            }
        }
       cnt++;
       for (int i=1; i<=n; i++)
            for (int j=1; j<=n; j++)
                if (!input[i][j])
               input[i][j]=cnt;

          for (int i=1;i<=n;i++){
             for (int j=1;j<=n;j++)
                 cout << input[i][j]<<" ";
          cout<
2
1 1 1 2 2 1
2
1 1 1 2 2 1
0
2
1 1 1 2 
3
1 1 2 2 3 3 1 2
2 3 2 1
3 1 3 2
0
3
1 1 2 2 3 3
2 3 2 1 1 2
3 1 3 2 1 3
0
3
1 1 2 2 3 3
2 3 2 1 1 2
3 1 3 2 1 3
0
3
1 1 2 2 3 3
2 3 2 1 1 2
0
3
1 1 2 2 3 3
2 3 2 1 1 2
0
3
1 1 2 2 3 3
2 3 2 1 1 2 3 1
0
3
1 1 1 2 1 3 2 1
2 2 2 3
3
1 1 1 2 1 3 
2 2 2 3 2 1
3
1 1 1 2 1 3 2 1
2 2 2 3 3 1
3
1 1 1 2 1 3 2 1
2 2 2 3 3 3
3
1 1 1 2 1 3 2 1
2 2 2 3 3 3
0
3
1 1 1 2 1 3 2 1
2 2 2 3 3 3
2
1 1 1 2
3
1 1 1 2 1 3 
2 2 2 3 2 1
0
#include 
2
1 2 2 1
0