Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
int x1,y1,H,W,s_x,s_y,g_y,g_x,sum1;
char S[20][20];
int sum1 = 0;

struct Object {
    int  x;
    int  y;
    int sum;
}
queue<Object> q;

vector<int> y_vec = {0, 0, -1, 1};
vector<int> x_vec = {-1, 1, 0, 0};
int bfs() {
    while(!q.empty()) {
        Object now = q.front(); q.pop();
        x1 = now.x;
        y1 = now.y;
        sum1 = now.sum;
        if(x1 == g_x && y1 == g_y) return sum1;
        
        for(int i = 0; i < 4; i++) {
            Object next = { x1 + x_vec[i], y1 + y_vec[i], sum1 + 1};
            if(0 <= next.y && next.y <= H - 1 && 0 <= next.x && next.y <= W - 1 && vec[next.y][next.x] == '.') {
                vec[next.y][next.x] = 'x';
                q.push(next);
            }
        }
    
    }
    return 0;
} 
int main() {
    
    cin >> H >> W;
    

    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cin >> S[i][j];
        }
    }
    int ans = 0;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
           if(S[i][j] == '.' ){
            Object start = { i, j, 0 }; 
            ans = max(ans, bfs()); }
        }
    }

    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc:5:8: error: 'int y1' redeclared as different kind of entity
    5 | int x1,y1,H,W,s_x,s_y,g_y,g_x,sum1;
      |        ^~
In file included from /usr/include/features.h:523,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:683,
                 from /usr/include/c++/14/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:33,
                 from a.cc:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:257:1: note: previous declaration 'double y1(double)'
  257 | __MATHCALL (y1,, (_Mdouble_));
      | ^~~~~~~~~~
a.cc:7:5: error: redefinition of 'int sum1'
    7 | int sum1 = 0;
      |     ^~~~
a.cc:5:31: note: 'int sum1' previously declared here
    5 | int x1,y1,H,W,s_x,s_y,g_y,g_x,sum1;
      |                               ^~~~
a.cc:14:15: error: invalid declarator before 'q'
   14 | queue<Object> q;
      |               ^
a.cc: In function 'int bfs()':
a.cc:19:12: error: 'q' was not declared in this scope
   19 |     while(!q.empty()) {
      |            ^
a.cc:22:12: error: assignment of function 'double y1(double)'
   22 |         y1 = now.y;
      |         ~~~^~~~~~~
a.cc:24:28: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   24 |         if(x1 == g_x && y1 == g_y) return sum1;
      |                         ~~~^~~~~~
a.cc:27:47: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   27 |             Object next = { x1 + x_vec[i], y1 + y_vec[i], sum1 + 1};
a.cc:27:47: error: invalid conversion from 'double (*)(double) noexcept' to 'int' [-fpermissive]
   27 |             Object next = { x1 + x_vec[i], y1 + y_vec[i], sum1 + 1};
a.cc:28:84: error: 'vec' was not declared in this scope; did you mean 'y_vec'?
   28 |             if(0 <= next.y && next.y <= H - 1 && 0 <= next.x && next.y <= W - 1 && vec[next.y][next.x] == '.') {
      |                                                                                    ^~~
      |                                                                                    y_vec