Language: C++

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

string a[25];
int n,m;
int bfs(pair<int,int>p1,pair<int,int>p2)
{
   queue<pair<int,int> >qq;
   qq.push(p1);
   map<pair<int,int>,int>dis;
   map<pair<int,int> ,int>mm;
   while(!qq.empty())
   {
      pair<int,int>pp=qq.front();
      qq.pop();
      if(pp.first>1)
      {
         if(a[pp.first-1][pp.second]=='.' && mm[{pp.first-1,pp.second}]==0)
         {
            dis[{pp.first-1,pp.second}]=dis[pp]+1;
            qq.push({pp.first-1,pp.second});
            mm[{pp.first-1,pp.second}]=1;
         }
      }
      if(pp.first<n)
      {
         if(a[pp.first+1][pp.second]=='.'&& mm[{pp.first+1,pp.second}]==0)
         {
            dis[{pp.first+1,pp.second}]=dis[pp]+1;
            qq.push({pp.first+1,pp.second});
            mm[{pp.first+1,pp.second}]=1;
         }
      }
      if(pp.second>1)
      {
         if(a[pp.first][pp.second-1]=='.'&& mm[{pp.first,pp.second-1}]==0)
         {
            dis[{pp.first,pp.second-1}]=dis[pp]+1;
            qq.push({pp.first,pp.second-1});
            mm[{pp.first,pp.second-1}]=1;
         }
      }
      if(pp.second<m)
      {
         if(a[pp.first][pp.second+1]=='.'&& mm[{pp.first,pp.second+1}]==0)
         {
            dis[{pp.first,pp.second+1}]=dis[pp]+1;
            qq.push({pp.first,pp.second+1});
            mm[{pp.first,pp.second+1}]=1;
         }
      }
   }
   return dis[p2];
}

signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
//  #ifndef ONLINE_JUDGE
//     freopen ("INPUT.txt" , "r" , stdin);
//     freopen ("OUTPUT.txt" , "w" , stdout);
//  #endif

// -------------------------------------Code starts here---------------------------------------------------------------------     

   cin>>n>>m;
   for(int i=1;i<=n;i++)
   {
      cin>>a[i];
      a[i]="$"+a[i];
   }
   int mx=0;
   pair<int,int>ind1,ind2;
   for(int i=1;i<=n;i++)
   {
      for(int j=1;j<=m;j++)
      {
      for(int k=1;k<=n;k++)
      {
         for(int l=1;l<=m;l++)
         {
            if(a[i][j]=='.' && a[k][l]=='.')
            {
               int z=bfs({i,j},{k,l});
               if(z>=mx)
               {
                  mx=z;
                  ind1={i,j};
                  ind2={k,l};
               }
            }
         }

      }

      }
3 5
...#.
.#.#.
.#...

      }

   cout<<mx;
// -------------------------------------Code ends here------------------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
    clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }

Compiler output:
a.cc:105:4: error: stray '#' in program
  105 | ...#.
      |    ^
a.cc:106:2: error: stray '#' in program
  106 | .#.#.
      |  ^
a.cc:106:4: error: stray '#' in program
  106 | .#.#.
      |    ^
a.cc:107:2: error: stray '#' in program
  107 | .#...
      |  ^
a.cc: In function 'int main()':
a.cc:104:2: error: expected ';' before numeric constant
  104 | 3 5
      |  ^~
      |  ;