function taking diffrent value than passed in c++ : I wrote a simple code for dfs using c++ , but the value that I am passing and the value that the function is accepting is diffrent .printing the values accepted by the function explains . Can you please help me out ?

    #include<bits/stdc++.h>
    using namespace std;
    void dfs(int i,int j);
    char graph[51][51];
    int n,m,loop=0,inx,iny,completed=0;
    
    int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int i,j,k,a,b,c;
    cin>>n>>m;
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            cin>>graph[i][j];
        }
    }
    for(i=1;i<=n,completed==0;i++){
        for(j=1;j<=m,completed==0;j++){
 
                inx=i;
                iny=j;
            dfs(i,j);
 
        }
 
    }
    if(completed==1)
        cout<<"YES\n";
    else cout<<"NO\n";
    
    
    return 0;
    }
    
    void dfs(int i,int j){
        cout<<i<<" "<<j<<"\n";      //for checking values taken by the function 
        if(completed)
            return;
    if(i==inx && j==iny){
        if(loop>=4)
            completed=1;
        return ;
    }
        // loop will increase exponentially !!!!!!
     int k=loop;
    if(j<m && graph[i][j]==graph[i][j+1]){
         loop++;
        dfs(i,j+1);
    }
    loop=k;
    if(j>1 && graph[i][j]==graph[i][j-1]){
        loop++;
        dfs(i,j-1);
    }
    loop=k;
    if(i>1 && graph[i][j]==graph[i-1][j]){
        loop++;
        dfs(i-1,j);
    }
    loop=k;
    if(i<n && graph[i][j]==graph[i+1][j]){
        loop++;
        dfs(i+1,j);
    }
    
    }


p.s.In case anyone is interested , I was trying [this question .][1]


  [1]: https://codeforces.com/problemset/problem/510/B