Language: C++

//hinagata.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
#include <iomanip>
#include <limits>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPi(i,a,b) for(int i=(a);i<(b);i++)
#define REPRi(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int checkaround(int H,int W,vector<vector<int>> M,pair<int,int> now,vector<vector<int>> &cost,vector<vector<int>> &arrival){
    int tate=now.first;
    int yoko=now.second;
    if(M[tate][yoko]==-1){
        return 0;
    }
    arrival[tate][yoko]=1;
    //上について処理
    if(tate>=1&&M[tate-1][yoko]!=-1){
        if(cost[tate-1][yoko]>cost[tate][yoko]+1){
            cost[tate-1][yoko]=cost[tate][yoko]+1;
        }
    }
    //下についての処理
    if(H-tate-1>=1&&M[tate+1][yoko]!=-1){
        if(cost[tate+1][yoko]>cost[tate][yoko]+1){
            cost[tate+1][yoko]=cost[tate][yoko]+1;
        }
    }
    //左についての処理
    if(yoko>=1&&M[tate][yoko-1]!=-1){
        if(cost[tate][yoko-1]>cost[tate][yoko]+1){
        cost[tate][yoko-1]=cost[tate][yoko]+1;
        }
    }
    //右についての処理
    if(W-yoko-1>=1&&M[tate][yoko+1]!=-1){
        if(cost[tate][yoko+1]>cost[tate][yoko]+1){
            cost[tate][yoko+1]=cost[tate][yoko]+1;
        }
    }
    int costmin=INT_MAX;
    pair<int,int> Nextp;
    REP(i,H){
        REP(j,W){
            if(arrival[i][j]!=1&&M[i][j]!=-1){
                if(costmin>cost[i][j]){
                    costmin=cost[i][j];
                    Nextp=make_pair(i,j);
                }
            }
        }
    }
    if(costmin!=INT_MAX){
        checkaround(H,W,M,Nextp,cost,arrival);
    }
    return 0;
}

int STpath(int H,int W,vector<vector<int>> M,pair<int,int> S,pair<int,int> T){
    vector<vector<int>> cost(H,vector<int> (W,INT_MAX));
    vector<vector<int>> arrival(H,vector<int> (W,-1));
    cost[S.first][S.second]=0;
    checkaround(H,W,M,S,cost,arrival);
    int costmax=0;
    REP(i,H){
        REP(j,W){
            if(costmax<cost[i][j]&&cost[i][j]!=INT_MAX){
                costmax=cost[i][j];
            }
        }
    }
    return costmax;
}

int main(){
    int H,W;
    cin>>H>>W;
    vector<vector<int>> M(H,vector<int> (W));
    REP(i,H){
        REP(j,W){
            char S;
            cin>>S;
            if(S=='.'){
                M[i][j]=1;
            }else if(S=='#'){
                M[i][j]=-1;
            }
        }
    }
    int maxcost=0;
    REP(i,H){
        REP(j,W){
            REP(k,H){
                REP(l,W){
                    int cost=STpath(H,W,M,make_pair(i,j),make_pair(k,l));
                    if(cost>maxcost){
                        maxcost=cost;
                    }
                }
            }
        }
    }
    cout<<maxcost<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int checkaround(int, int, std::vector<std::vector<int> >, std::pair<int, int>, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&)':
a.cc:53:17: error: 'INT_MAX' was not declared in this scope
   53 |     int costmin=INT_MAX;
      |                 ^~~~~~~
a.cc:12:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   11 | #include <iomanip>
  +++ |+#include <climits>
   12 | #include <limits>
a.cc: In function 'int STpath(int, int, std::vector<std::vector<int> >, std::pair<int, int>, std::pair<int, int>)':
a.cc:72:47: error: 'INT_MAX' was not declared in this scope
   72 |     vector<vector<int>> cost(H,vector<int> (W,INT_MAX));
      |                                               ^~~~~~~
a.cc:72:47: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'