Language: C++

#include<bits/stdc++.h>
//#include<stack>
using namespace std;

int cie[500][500];
int visit[500][500];

typedef struct position{
    int y;
    int x;
    int hater;
}pos;

int hate(int row, int col, int n, int visit[500][500]){
    int result = INT_MAX;
    //int counter = 0;
    queue<pos*> q;
    int ny, nx;
    int l_visit[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            l_visit[i][j] = 0;
        }
    }

    vector< pair<int,int> > mov;
    mov.push_back(make_pair(0,1));
    mov.push_back(make_pair(0,-1));
    mov.push_back(make_pair(1,0));
    mov.push_back(make_pair(-1,0));

    l_visit[row][col] = 1;
    visit[row][col] = 1;

    if(row == 0 || row == n-1 || col==0 || col== n-1) return 0;

    pos* current = new pos;
    current->y = row;
    current->x = col;
    current->hater = 0;
    q.push(current);
    int haters;
    //cout << "push: " << y << " " << x << endl;
    while(!q.empty()){
        current = q.front();
        row = current->y;
        col = current->x;
        haters = current->hater;
        q.pop();

        for(int j=0;j<4;j++){
            pos* child = new pos;
            ny = row + mov[j].first;
            nx = col + mov[j].second;
            child->y = ny;
            child->x = nx;

            if( visit[ny][nx] && !l_visit[ny][nx])  child->hater = haters;
            else if( !visit[ny][nx] && !l_visit[ny][nx])  child->hater = haters+1;

            if( ny >= 0 && nx >= 0 && ny <= n-1 && nx <= n-1){
                if( ny == 0 || nx == 0 || ny == n-1 || nx == n-1 && !l_visit[ny][nx]){
                    result = child->hater < result ? child->hater:result;
                    l_visit[ny][nx] = 1;
                    //cout << "(" << ny << "," << nx << "):" << result << " \n";
                }
                else if( !l_visit[ny][nx]){
                    q.push(child);
                    l_visit[ny][nx] = 1;
                }
            }

        }
    }
    return result;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, num, y, x, counter = 0;
    int result;
    cin >> n;

    for( int i =0;i<n*n;i++){
        cin >> num;
        if(num%n == 0) y = num / n - 1;
        else y = num / n;
        x = num - n*y - 1;

        result = hate( y, x, n, visit);
        //cout << "result " << num << ":" << result << endl;
        counter += result;
        //if(!result) counter++;
        //cout << i << ": " << counter << endl;
    }
    cout << counter;


    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:92:33: error: reference to 'visit' is ambiguous
   92 |         result = hate( y, x, n, visit);
      |                                 ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:6:5: note:                 'int visit [500][500]'
    6 | int visit[500][500];
      |     ^~~~~