Language: C++

/*
        quu..__
         $$$b  `---.__
          "$$b        `--.                          ___.---uuudP
           `$$b           `.__.------.__     __.---'      $$$$"              .
             "$b          -'            `-.-'            $$$"              .'|
               ".                                       d$"             _.'  |
                 `.   /      @Rrrrya                 ..."             .'     |
                   `./                           ..::-'            _.'       |
                    /                         .:::-'            .-'         .'
                   :                          ::''\          _.'            |
                  .' .-.             .-.           `.      .'               |
                  : /'$$|           .@"$\           `.   .'              _.-'
                 .'|$u$$|          |$$,$$|           |  <            _.-'
                 | `:$$:'          :$$$$$:           `.  `.       .-'
                 :                  `"--'             |    `-.     \
                :##.       ==             .###.       `.      `.    `\
                |##:                      :###:        |        >     >
                |#'     `..'`..'          `###'        x:      /     /
                 \                                   xXX|     /    ./
                  \                                xXXX'|    /   ./
                  /`-.                                  `.  /   /
                 :    `-  ...........,                   | /  .'
                 |         ``:::::::'       .            |<    `.
                 |             ```          |           x| \ `.:``.
                 |                         .'    /'   xXX|  `:`M`M':.
                 |    |                    ;    /:' xXXX'|  -'MMMMM:'
                 `.  .'                   :    /:'       |-'MMMM.-'
                  |  |                   .'   /'        .'MMM.-'
                  `'`'                   :  ,'          |MMM<
                    |                     `'            |tbap\
                     \                                  :MM.-'
                      \                 |              .''
                       \.               `.            /
                        /     .:::::::.. :           /
                       |     .:::::::::::`.         /
                       |   .:::------------\       /
                      /   .''               >::'  /
                      `',:                 :    .'
                                           `:.:'   
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define mod 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))
#define cio ios::sync_with_stdio(false)
int next[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
int s[300010];
int vis[550][550];
int jud[550][550];
int cnt = 0;
int minn;
int n;
void dfs(int x, int y, int step)
{   
    jud[x][y] = 1;
    if(x==1||y==1||x==n||y==n){
        minn = min(minn,step);
        return;
    }
    for(int i = 0; i < 4; i++){
        int xx = x+next[i][0];
        int yy = y+next[i][1];
        if(!jud[xx][yy]){
            jud[xx][yy] = 1;
            if(vis[xx][yy]==0){
                dfs(xx,yy,step);
            }else{
                dfs(xx,yy,step+1);
            }
            jud[xx][yy] = 0;
        }
    }   
}
int main()
{
    cin >> n;
    for(int i = 1; i <= n*n; i++) cin >> s[i];
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++) vis[i][j] =(i-1)*n+j;
    }
    for(int i = 1; i <= n*n; i++){
        int x;
        if(s[i]%n==0){
            x = s[i]/n;
        }else{
            x = (s[i]+n)/n;
        }
        int y = s[i]%n;
        if(y==0) y = n;
        if(x==1||y==1||x==n||y==n){
            vis[x][y] = 0;
            continue;
        }
        minn = mod;
        mem(jud);
        dfs(x,y,0);
        vis[x][y] = 0;
        cnt += minn;
    }
    cout << cnt << endl;
    return 0;
}


Compiler output:
a.cc: In function 'void dfs(int, int, int)':
a.cc:65:20: error: reference to 'next' is ambiguous
   65 |         int xx = x+next[i][0];
      |                    ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:42:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:50:5: note:                 'int next [4][2]'
   50 | int next[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
      |     ^~~~
a.cc:66:20: error: reference to 'next' is ambiguous
   66 |         int yy = y+next[i][1];
      |                    ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:50:5: note:                 'int next [4][2]'
   50 | int next[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
      |     ^~~~