Language: C++

ｖ#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int H, W;
vector<string> Graph(21);

int solve(int i, int j, int k, int l) {
    if (Graph[i][j] == '#' || Graph[k][l] == '#') return 0;

    vector<vector<int>> dist(H, vector<int>(W, -1));  // -1: 未訪問
    queue<P> que;

    que.push(make_pair(i, j));  // スタート地点をプッシュ
    dist[i][j] = 0;

    while (!que.empty()) {
        P p = que.front();
        que.pop();
        for (int direction = 0; direction < 4; ++direction) {
            int nh = p.first + dx[direction];
            int nw = p.second + dy[direction];
            if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
            if (dist[nh][nw] > -1) continue;
            if (Graph[nh][nw] == '#') continue;
            dist[nh][nw] = dist[p.first][p.second] + 1;
            if (nh == k && nw == l) {
                //ゴール
                return dist[k][l];
            }
            que.push(make_pair(nh, nw));
        }
    }
    return 0;
}

int main() {
    cin >> H >> W;
    rep(i, H) cin >> Graph.at(i);

    int ans = 0;
    rep(i, H) rep(j, W) rep(k, H) rep(l, W) {
        ans = max(ans, solve(i, j, k, l));
    }

    cout << ans << endl;
}


Compiler output:
a.cc:1:3: error: stray '#' in program
    1 | ｖ#include <bits/stdc++.h>
      |   ^
a.cc:1:1: error: '\U0000ff56' does not name a type
    1 | ｖ#include <bits/stdc++.h>
      | ^~
a.cc:5:11: error: 'pair' does not name a type
    5 | using P = pair<int, int>;
      |           ^~~~
a.cc:11:1: error: 'vector' does not name a type
   11 | vector<string> Graph(21);
      | ^~~~~~
a.cc: In function 'int solve(int, int, int, int)':
a.cc:14:9: error: 'Graph' was not declared in this scope
   14 |     if (Graph[i][j] == '#' || Graph[k][l] == '#') return 0;
      |         ^~~~~
a.cc:16:5: error: 'vector' was not declared in this scope
   16 |     vector<vector<int>> dist(H, vector<int>(W, -1));  // -1: 未訪問
      |     ^~~~~~
a.cc:16:19: error: expected primary-expression before 'int'
   16 |     vector<vector<int>> dist(H, vector<int>(W, -1));  // -1: 未訪問
      |                   ^~~
a.cc:17:5: error: 'queue' was not declared in this scope
   17 |     queue<P> que;
      |     ^~~~~
a.cc:17:11: error: 'P' was not declared in this scope
   17 |     queue<P> que;
      |           ^
a.cc:17:14: error: 'que' was not declared in this scope
   17 |     queue<P> que;
      |              ^~~
a.cc:19:14: error: 'make_pair' was not declared in this scope
   19 |     que.push(make_pair(i, j));  // スタート地点をプッシュ
      |              ^~~~~~~~~
a.cc:20:5: error: 'dist' was not declared in this scope
   20 |     dist[i][j] = 0;
      |     ^~~~
a.cc:23:10: error: expected ';' before 'p'
   23 |         P p = que.front();
      |          ^~
      |          ;
a.cc:26:22: error: 'p' was not declared in this scope
   26 |             int nh = p.first + dx[direction];
      |                      ^
a.cc:30:17: error: 'Graph' was not declared in this scope
   30 |             if (Graph[nh][nw] == '#') continue;
      |                 ^~~~~
a.cc: In function 'int main()':
a.cc:43:5: error: 'cin' was not declared in this scope
   43 |     cin >> H >> W;
      |     ^~~
a.cc:44:22: error: 'Graph' was not declared in this scope
   44 |     rep(i, H) cin >> Graph.at(i);
      |                      ^~~~~
a.cc:48:15: error: 'max' was not declared in this scope
   48 |         ans = max(ans, solve(i, j, k, l));
      |               ^~~
a.cc:51:5: error: 'cout' was not declared in this scope
   51 |     cout << ans << endl;
      |     ^~~~
a.cc:51:20: error: 'endl' was not declared in this scope
   51 |     cout << ans << endl;
      |                    ^~~~