For this Question: Given a binary matrix of size N x M. The task is to find the distance of nearest 1 in the matrix for each cell. The distance is calculated as |i1 – i2| + |j1 – j2|, where i1, j1 are the row number and column number of the current cell and i2, j2 are the row number and column number of the nearest cell having value 1.The first line contains two integers N and M, denoting the number of rows and columns of the matrix. Next N lines contain M integers either 0 or 1.

1 <= T <= 20
1 <= N, M <= 500
Each element of matrix is either 0 or 1
It is guaranteed that there is at least one 1 present in the input.Print N lines. Each line containing M integers denoting the distance from nearest 1.Sample Input:
3 3
1 0 0
0 1 0
0 0 0

Sample Output:
0 1 2 
1 0 1 
2 1 2, I have written this Solution Code: #include<bits/stdc++.h>
#define int         long long
#define ld          long double
#define ll          long long
#define pb          push_back
#define endl        '\n'
#define pi          pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define se          second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define dep(i,a,b)  for(int i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

const int N = 500 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

int a[N][N], vis[N][N];

void solve(){
    int n, m;
    cin >> n >> m;
    queue<pi> q;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> a[i][j];
            if(a[i][j])
                q.push({i, j}), vis[i][j] = 1;
        }
    }
    int f[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1};
    while(!q.empty()){
        pi x = q.front();
        q.pop();
        for(int i = 0; i < 4; i++){
            int nx = x.fi + f[i][0];
            int ny = x.se + f[i][1];
            if(nx >= 1 && nx <= n && ny >= 1 && ny <= m && vis[nx][ny] == 0){
                vis[nx][ny] = vis[x.fi][x.se] + 1;
                q.push({nx, ny});
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++)
            cout << vis[i][j] - 1 << " ";
        cout << endl;
    }
}

void testcases(){
    int tt = 1; 
    //cin >> tt;
    while(tt--){
        solve();
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

 		clock_t start = clock();
 	

    testcases();


 		cerr << (double)(clock() - start)*1000/CLOCKS_PER_SEC << " ms: ";
    return 0;
}, In this Programming Language: C++, Now tell me if this Code is compilable or not?