Help me in solving MINCOLOR problem

My issue

help me to solve this problem

My code

//Radhe Radhe
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const ll M = 998244353;
ll add(ll x, ll y)  { return (x%M + y%M)%M; }
ll sub(ll x, ll y)  { return (x%M - y%M + M)%M;}
ll mul(ll x, ll y)  { return (x%M * y%M)%M; }
void print(vector<ll>v1){
for(auto x:v1){cout<<x<<" ";}
cout<<endl;}
ll binexp(ll a,ll b){
ll res = 1;
while(b){
if(b&1)res = ((res%M)*(a%M)%M);
a = ((a%M)*(a%M)%M);
 b>>=1LL;
}
return res%M;
}
void Radhe(){
 ll t;
 cin>>t;
 while(t--){
    ll n,m;
    cin>>n>>m;
    vector<vector<ll>>mat(n+2,vector<ll>(m+2,0));
    ll x1,y1;
    cin>>x1>>y1;
    mat[x1][y1]=1;
    ll x2,y2;
    cin>>x2>>y2;
    mat[x2][y2]=2;
    
    for(int i = 1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(mat[i][j])continue;
            vector<bool>v1(4,false);
            if(mat[i-1][j])v1[mat[i-1][j]]=true;
            if(mat[i][j-1])v1[mat[i][j-1]]=true;
            if(mat[i][j+1])v1[mat[i][j+1]]=true;
            if(mat[i+1][j])v1[mat[i+1][j]]=true;
            for(int k=1;k<4;k++){
                if(!v1[k]){mat[i][j]=k;
                    break;
                }
                
            }
            // cout<<endl;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++)cout<<mat[i][j]<<" ";
        cout<<endl;
    }
 }
}
int main(){
Radhe();
return 0;
}

Problem Link: Minimum Coloring Practice Coding Problem - CodeChef

@jaggadaku005
hint :- just perform the bipartite check for the matrix if its valid then print that result else print any other number in the empty cells.

1 Like