Language: C++

3 5
...#.
.#.#.
.#...#include <bits/stdc++.h>
#define Int long long
#define pb push_back
using namespace std;


Int N,M,K;
Int X,Y,Z,D;
const int MAXN=105;
Int B,C;


struct DisJointSet{
    vector<int> SZ;
    vector<int> ID;
    int n;

    DisJointSet(int n){
        SZ.resize(n);
        ID.resize(n);
        this->n=n;
        
        for(int i=0;i<n;++i){
            ID[i]=i;
            SZ[i]=1;
        }
    }
    
    int find(int x){
        return (ID[x]==x ? x:find(ID[x]));
    }
    
    void Union_find(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(SZ[x]>SZ[y]){
            ID[y]=x;
            SZ[x]+=SZ[y];
        }
        else{
            ID[x]=y;
            SZ[y]+=SZ[x];
        }
        return;
    }
};
vector<pair<int,int>> dir{{-1,0},{0,-1},{0,1},{1,0}};
Int shortestPath(vector<vector<int>> grid,pair<int,int> start,pair<int,int> end){
    queue<pair<int,int>> q;
    q.push(start);
    int iter=0;
    while(!q.empty()){
        int tt=q.size();
        while(tt--){
            auto u=q.front();
            q.pop();
            if(u==end) return iter;
            for(auto itr:dir){
                int x=u.first+itr.first;
                int y=u.second+itr.second;
                if(x<0||y<0||x>=grid.size()||y>=grid[0].size()||!grid[x][y]) continue;
                grid[x][y]=0;
                q.push({x,y});
            }
            
        }
        ++iter;
    }
    
}

int main()
{
    cin>>N>>M;
    vector<vector<int>> grid(N,vector<int>(M,0));
    for(int i=0;i<N;++i){
        for(int j=0;j<M;++j){
            char x;cin>>x;
            grid[i][j]=(x=='.' ? 1:0);
        }
    }
    Int ans=-1e9;
    for(int i=0;i<N;++i){
        for(int j=0;j<M;++j){
            for(int x=0;x<N;++x){
                for(int y=0;y<M;++y){
                    if(!grid[i][j]||!grid[x][y]) continue;
                    ans=max(ans,shortestPath(grid,{i,j},{x,y}));
                }
            }
        }
    }
    cout<<ans<<"\n";
}

Compiler output:
a.cc:2:4: error: stray '#' in program
    2 | ...#.
      |    ^
a.cc:3:2: error: stray '#' in program
    3 | .#.#.
      |  ^
a.cc:3:4: error: stray '#' in program
    3 | .#.#.
      |    ^
a.cc:4:2: error: stray '#' in program
    4 | .#...#include <bits/stdc++.h>
      |  ^
a.cc:4:6: error: stray '#' in program
    4 | .#...#include <bits/stdc++.h>
      |      ^
a.cc:1:1: error: expected unqualified-id before numeric constant
    1 | 3 5
      | ^
a.cc:17:5: error: 'vector' does not name a type
   17 |     vector<int> SZ;
      |     ^~~~~~
a.cc:18:5: error: 'vector' does not name a type
   18 |     vector<int> ID;
      |     ^~~~~~
a.cc: In constructor 'DisJointSet::DisJointSet(int)':
a.cc:22:9: error: 'SZ' was not declared in this scope; did you mean 'Z'?
   22 |         SZ.resize(n);
      |         ^~
      |         Z
a.cc:23:9: error: 'ID' was not declared in this scope; did you mean 'D'?
   23 |         ID.resize(n);
      |         ^~
      |         D
a.cc: In member function 'int DisJointSet::find(int)':
a.cc:33:17: error: 'ID' was not declared in this scope; did you mean 'D'?
   33 |         return (ID[x]==x ? x:find(ID[x]));
      |                 ^~
      |                 D
a.cc: In member function 'void DisJointSet::Union_find(int, int)':
a.cc:40:12: error: 'SZ' was not declared in this scope; did you mean 'Z'?
   40 |         if(SZ[x]>SZ[y]){
      |            ^~
      |            Z
a.cc:41:13: error: 'ID' was not declared in this scope; did you mean 'D'?
   41 |             ID[y]=x;
      |             ^~
      |             D
a.cc:45:13: error: 'ID' was not declared in this scope; did you mean 'D'?
   45 |             ID[x]=y;
      |             ^~
      |             D
a.cc: At global scope:
a.cc:51:1: error: 'vector' does not name a type
   51 | vector<pair<int,int>> dir{{-1,0},{0,-1},{0,1},{1,0}};
      | ^~~~~~
a.cc:52:18: error: 'vector' was not declared in this scope
   52 | Int shortestPath(vector<vector<int>> grid,pair<int,int> start,pair<int,int> end){
      |                  ^~~~~~
a.cc:52:25: error: 'vector' was not declared in this scope
   52 | Int shortestPath(vector<vector<int>> grid,pair<int,int> start,pair<int,int> end){
      |                         ^~~~~~
a.cc:52:32: error: expected primary-expression before 'int'
   52 | Int shortestPath(vector<vector<int>> grid,pair<int,int> start,pair<int,int> end){
      |                                ^~~
a.cc:52:43: error: 'pair' was not declared in this scope
   52 | Int shortestPath(vector<vector<int>> grid,pair<int,int> start,pair<int,int> end){
      |                                           ^~~~
a.cc:52:48: error: expected primary-expression before 'int'
   52 | Int shortestPath(vector<vector<int>> grid,pair<int,int> start,pair<int,int> end){
      |                                                ^~~
a.cc:52:52: error: expected primary-expression before 'int'
   52 | Int shortestPath(vector<vector<int>> grid,pair<int,int> start,pair<int,int> end){
      |                                                    ^~~
a.cc:52:63: error: 'pair' was not declared in this scope
   52 | Int shortestPath(vector<vector<int>> grid,pair<int,int> start,pair<int,int> end){
      |                                                               ^~~~
a.cc:52:68: error: expected primary-expression before 'int'
   52 | Int shortestPath(vector<vector<int>> grid,pair<int,int> start,pair<int,int> end){
      |                                                                    ^~~
a.cc:52:72: error: expected primary-expression before 'int'
   52 | Int shortestPath(vector<vector<int>> grid,pair<int,int> start,pair<int,int> end){
      |                                                                        ^~~
a.cc:52:80: error: expression list treated as compound expression in initializer [-fpermissive]
   52 | Int shortestPath(vector<vector<int>> grid,pair<int,int> start,pair<int,int> end){
      |                                                                                ^
a.cc: In function 'int main()':
a.cc:78:5: error: 'cin' was not declared in this scope
   78 |     cin>>N>>M;
      |     ^~~
a.cc:79:5: error: 'vector' was not declared in this scope
   79 |     vector<vector<int>> grid(N,vector<int>(M,0));
      |     ^~~~~~
a.cc:79:19: error: expected primary-expression before 'int'
   79 |     vector<vector<int>> grid(N,vector<int>(M,0));
      |                   ^~~
a.cc:83:13: error: 'grid' was not declared in this scope
   83 |             grid[i][j]=(x=='.' ? 1:0);
      |             ^~~~
a.cc:91:25: error: 'grid' was not declared in this scope
   91 |                     if(!grid[i][j]||!grid[x][y]) continue;
      |                         ^~~~
a.cc:92:46: error: 'grid' was not declared in this scope
   92 |                     ans=max(ans,shortestPath(grid,{i,j},{x,y}));
      |                                              ^~~~
a.cc:92:45: error: 'shortestPath' cannot be used as a function
   92 |                     ans=max(ans,shortestPath(grid,{i,j},{x,y}));
      |                                 ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
a.cc:92:25: error: 'max' was not declared in this scope
   92 |                     ans=max(ans,shortestPath(grid,{i,j},{x,y}));
      |                         ^~~
a.cc:97:5: error: 'cout' was not declared in this scope
   97 |     cout<<ans<<"\n";
      |     ^~~~