Language: C++

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.Scanner;
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}else{
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}
	public double nextDouble() { return Double.parseDouble(next());}
	public char nextchar() {
		try { return (char)System.in.read(); } catch(Exception e) {
			throw new RuntimeException(e);
		}
	}
}
public class Main {
	static FastScanner scan=new FastScanner();
	static Scanner scanner=new Scanner(System.in);
	static long mod=1000000007;
	static double eps=0.0000000001;
	static int big=Integer.MAX_VALUE;
	static long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}
	static long lcm (long a, long b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long lmax(long a,long b) {return Math.max(a, b);}
	static long lmin(long a,long b) {return Math.min(a, b);}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int right=a.length;
		int left=0;
		while(right-left>0) {
			int mid=(right+left)/2;
			if(a[mid]<key) {
				left=mid;
			}
			else {
				right=mid;
			}
		}
		return left;
	}
	static int upper_bound(int a[],int key) {
		int right=a.length;
		int left=0;
		while(right-left>0) {
			int mid=(right+left)/2;
			if(a[mid]<=key) {
				left=mid;
			}
			else {
				right=mid;
			}
		}
		return left;
	}
	static boolean isPrime (long n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int upper_division(int a,int b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lupper_division(long a,long b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static int[] setArray(int a) {
		int b[]=new int[a];
		for(int i=0;i<a;i++) {
			b[i]=scan.nextInt();
		}
		return b;
	}
	static long[] lsetArray(int a) {
		long b[]=new long[a];
		for(int i=0;i<a;i++) {
			b[i]=scan.nextLong();
		}
		return b;
	}
	static String reverce(String str) {
		String strr="";
		for(int i=str.length()-1;i>=0;i--) {
			strr+=str.charAt(i);
		}
		return strr;
	}
	public static void printArray(int[] que) {
		for(int i=0;i<que.length-1;i++) {
			System.out.print(que[i]+" ");
		}
		System.out.println(que[que.length-1]);
	}
	public static int[][] doublesort(int[][]a) {
		Arrays.sort(a,(x,y)->Integer.compare(x[0],y[0]));
		return a;
	}
	static long modpow(long x,long n,long mo) {
		long sum=1;
		while(n>0) {
			if((n&1)==1) {
				sum=sum*x%mo;
			}
			x=x*x%mo;
			n>>=1;
		}
		return sum;
	}
	public static char[] revch(char ch[]) {
		char ret[]=new char[ch.length];
		for(int i=ch.length-1,j=0;i>=0;i--,j++) {
			ret[j]=ch[i];
		}
		return ret;
	}
	public static int[] revint(int ch[]) {
		int ret[]=new int[ch.length];
		for(int i=ch.length-1,j=0;i>=0;i--,j++) {
			ret[j]=ch[i];
		}
		return ret;
	}
	public static void warshall_floyd(int v[][],int n) {
		for(int k=0;k<n;k++)
			for(int i=0;i<n;i++)
				for(int j=0;j<n;j++)
					v[i][j]=min(v[i][j],v[i][k]+v[k][j]);
	}
	public static long modinv(long a,long m) {
		long b=m,u=1,v=0;
		while(b!=0) {
			long t=a/b;
			a-=t*b;
			long x=a;
			a=b;
			b=x;
			
			u-=t*v;
			x=u;
			u=v;
			v=x;
		}
		u%=m;
		if(u<0)u+=m;
		return u;
	}
	public static void main(String[] args) {
		int n=scan.nextInt();
		int m=scan.nextInt();
		char ch[][]=new char[n][m];
		for(int i=0;i<n;i++)ch[i]=scan.next().toCharArray();
		Queue<Integer> MAP=new ArrayDeque<>();
		int ans=0;
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				if(ch[i][j]=='#')continue;
				MAP.add(i);
				MAP.add(j);
				MAP.add(0);
				char c[][]=new char[n][m];
				for(int z=0;z<n;z++)c[z]=ch[z].clone();
				int COST=0;
				for(;;) {
					if(MAP.size()==0) {
						break;
					}
					int x=MAP.poll();
					int y=MAP.poll();
					int cost=MAP.poll();
					COST=max(COST,cost);
					c[x][y]='#';
					if(x!=0) {
						if(c[x-1][y]=='.') {
							MAP.add(x-1);
							MAP.add(y);
							MAP.add(cost+1);
						}
					}
					if(x!=n-1) {
						if(c[x+1][y]=='.') {
							MAP.add(x+1);
							MAP.add(y);
							MAP.add(cost+1);
						}
					}
					if(y!=0) {
						if(c[x][y-1]=='.') {
							MAP.add(x);
							MAP.add(y-1);
							MAP.add(cost+1);
						}
					}
					if(y!=m-1) {
						if(c[x][y+1]=='.') {
							MAP.add(x);
							MAP.add(y+1);
							MAP.add(cost+1);
						}
					}
				}
				ans=max(ans,COST);
			}
		}
		System.out.println(ans);
	}
}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.io.IOException;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import java.io.InputStream;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import java.util.ArrayDeque;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import java.util.Arrays;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
    5 | import java.util.NoSuchElementException;
      | ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:1: error: 'import' does not name a type
    6 | import java.util.Queue;
      | ^~~~~~
a.cc:6:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:7:1: error: 'import' does not name a type
    7 | import java.util.Scanner;
      | ^~~~~~
a.cc:7:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:9:16: error: expected ':' before 'final'
    9 |         private final InputStream in = System.in;
      |                ^~~~~~
      |                :
a.cc:9:17: error: 'final' does not name a type
    9 |         private final InputStream in = System.in;
      |                 ^~~~~
a.cc:10:16: error: expected ':' before 'final'
   10 |         private final byte[] buffer = new byte[1024];
      |                ^~~~~~
      |                :
a.cc:10:17: error: 'final' does not name a type
   10 |         private final byte[] buffer = new byte[1024];
      |                 ^~~~~
a.cc:11:16: error: expected ':' before 'int'
   11 |         private int ptr = 0;
      |                ^~~~
      |                :
a.cc:12:16: error: expected ':' before 'int'
   12 |         private int buflen = 0;
      |                ^~~~
      |                :
a.cc:13:16: error: expected ':' before 'boolean'
   13 |         private boolean hasNextByte() {
      |                ^~~~~~~~
      |                :
a.cc:13:17: error: 'boolean' does not name a type; did you mean 'bool'?
   13 |         private boolean hasNextByte() {
      |                 ^~~~~~~
      |                 bool
a.cc:29:16: error: expected ':' before 'int'
   29 |         private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
      |                ^~~~
      |                :
a.cc:30:16: error: expected ':' before 'static'
   30 |         private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
      |                ^~~~~~~
      |                :
a.cc:30:24: error: 'boolean' does not name a type; did you mean 'bool'?
   30 |         private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
      |                        ^~~~~~~
      |                        bool
a.cc:31:15: error: expected ':' before 'boolean'
   31 |         public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
      |               ^~~~~~~~
      |               :
a.cc:31:16: error: 'boolean' does not name a type; did you mean 'bool'?
   31 |         public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
      |                ^~~~~~~
      |                bool
a.cc:32:15: error: expected ':' before 'String'
   32 |         public String next() {
      |               ^~~~~~~
      |               :
a.cc:32:16: error: 'String' does not name a type
   32 |         public String next() {
      |                ^~~~~~
a.cc:42:15: error: expected ':' before 'long'
   42 |         public long nextLong() {
      |               ^~~~~
      |               :
a.cc:66:15: error: expected ':' before 'int'
   66 |         public int nextInt() {
      |               ^~~~
      |               :
a.cc:71:15: error: expected ':' before 'double'
   71 |         public double nextDouble() { return Double.parseDouble(next());}
      |               ^~~~~~~
      |               :
a.cc:72:15: error: expected ':' before 'char'
   72 |         public char nextchar() {
      |               ^~~~~
      |               :
a.cc:77:2: error: expected ';' after class definition
   77 | }
      |  ^
      |  ;
a.cc: In member function 'int FastScanner::readByte()':
a.cc:29:38: error: 'hasNextByte' was not declared in this scope
   29 |         private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
      |                                      ^~~~~~~~~~~
a.cc:29:60: error: 'buffer' was not declared in this scope; did you mean 'buflen'?
   29 |         private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
      |                                                            ^~~~~~
      |                                                            buflen
a.cc: In member function 'long int FastScanner::nextLong()':
a.cc:43:22: error: 'hasNext' was not declared in this scope
   43 |                 if (!hasNext()) throw new NoSuchElementException();
      |                      ^~~~~~~
a.cc:43:43: error: expected type-specifier before 'NoSuchElementException'
   43 |                 if (!hasNext()) throw new NoSuchElementException();
      |                                           ^~~~~~~~~~~~~~~~~~~~~~
a.cc:45:17: error: 'boolean' was not declared in this scope; did you mean 'bool'?
   45 |                 boolean minus = false;
      |                 ^~~~~~~
      |                 bool
a.cc:48:25: error: 'minus' was not declared in this scope
   48 |                         minus = true;
      |                         ^~~~~
a.cc:52:35: error: expected type-specifier before 'NumberFormatException'
   52 |                         throw new NumberFormatException();
      |                                   ^~~~~~~~~~~~~~~~~~~~~
a.cc:58:46: error: 'isPrintableChar' was not declared in this scope
   58 |                         }else if(b == -1 || !isPrintableChar(b)){
      |                                              ^~~~~~~~~~~~~~~
a.cc:59:40: error: 'minus' was not declared in this scope
   59 |                                 return minus ? -n : n;
      |                                        ^~~~~
a.cc:61:43: error: expected type-specifier before 'NumberFormatException'
   61 |                                 throw new NumberFormatException();
      |                                           ^~~~~~~~~~~~~~~~~~~~~
a.cc: In member function 'int FastScanner::nextInt()':
a.cc:68:26: error: 'Integer' was not declared in this scope
   68 |                 if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
      |                          ^~~~~~~
a.cc:68:81: error: expected type-specifier before 'NumberFormatException'
   68 |                 if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
      |                                                                                 ^~~~~~~~~~~~~~~~~~~~~
a.cc: In member function 'double FastScanner::nextDouble()':
a.cc:71:45: error: 'Double' was not declared in this scope; did you mean 'double'?
   71 |         public double nextDouble() { return Double.parseDouble(next());}
      |                                             ^~~~~~
      |                                             double
a.cc:71:64: error: 'next' was not declared in this scope; did you mean 'nextInt'?
   71 |         public double nextDouble() { return Double.parseDouble(next());}
      |                                                                ^~~~
      |                                                                nextInt
a.cc: In member function 'char FastScanner::nextchar()':
a.cc:73:36: error: 'System' was not declared in this scope
   73 |                 try { return (char)System.in.read(); } catch(Exception e) {
      |                                    ^~~~~~
a.cc:73:62: error: 'Exception' does not name a type
   73 |                 try { return (char)System.in.read(); } catch(Exception e) {
      |                                                              ^~~~~~~~~
a.cc:74:35: error: expected type-specifier before 'RuntimeException'
   74 |                         throw new RuntimeException(e);
      |                                   ^~~~~~~~~~~~~~~~
a.cc: At global scope:
a.cc:78:1: error: expected unqualified-id before 'public'
   78 | public class Main {
      | ^~~~~~