Language: C++

#include<iostream>
#include<queue>
using namespace std;
int main() {

	//D
	int h, w;
	cin >> h >> w;
	int i, j;
	char s[20][20];
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			cin >> s[i][j];
		}
	}
	char p[20][20];
	queue<pair<int, int>> que;
	pair<int, int> start;
	int maxl = 0;
	//スタートを任意に選び、そこから最も遠い点を探す
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			memset(p, -1, sizeof(p));
			if (s[i][j] == '.') {
				p[i][j] = 0;
				que.push(pair<int, int>(i, j));
				while (que.size()) {
					start = que.front(); que.pop();
					if (start.first > 0) {
						if (s[start.first - 1][start.second] == '.') {
							if (p[start.first - 1][start.second] == -1) {
								que.push(pair<int, int>(start.first - 1, start.second));
								p[start.first - 1][start.second] = p[start.first][start.second] + 1;
								if (p[start.first - 1][start.second] > maxl)maxl = p[start.first - 1][start.second];
							}
						}
					}
					if (start.first < h - 1) {
						if (s[start.first + 1][start.second] == '.') {
							if (p[start.first + 1][start.second] == -1) {
								que.push(pair<int, int>(start.first + 1, start.second));
								p[start.first + 1][start.second] = p[start.first][start.second] + 1;
								if (p[start.first + 1][start.second] > maxl)maxl = p[start.first + 1][start.second];
							}
						}
					}
					if (start.second > 0) {
						if (s[start.first][start.second - 1] == '.') {
							if (p[start.first][start.second - 1] == -1) {
								que.push(pair<int, int>(start.first, start.second - 1));
								p[start.first][start.second - 1] = p[start.first][start.second] + 1;
								if (p[start.first][start.second - 1] > maxl)maxl = p[start.first][start.second - 1];
							}
						}
					}
					if (start.second < w - 1) {
						if (s[start.first][start.second + 1] == '.') {
							if (p[start.first][start.second + 1] == -1) {
								que.push(pair<int, int>(start.first, start.second + 1));
								p[start.first][start.second + 1] = p[start.first][start.second] + 1;
								if (p[start.first][start.second + 1] > maxl)maxl = p[start.first][start.second + 1];
							}
						}
					}
				}
			}

		}
	}
	cout << maxl << endl;
	return 0;


	//C
	/*int n, m;
	cin >> n >> m;
	int AC[100000];
	int WA[100000];
	int i, p;
	for (i = 0; i < n; i++) {
		AC[i] = 0;
		WA[i] = 0;
	}

	string s;
	for (i = 0; i < m; i++) {
		cin >> p;
		cin >> s;
		if (s == "AC") {
			AC[p - 1]++;
		}else{
			if(AC[p-1]==0)WA[p - 1]++;
		}
	}
	int pn = 0, sc = 0;
	for (i = 0; i < n; i++) {
		if (AC[i] > 0) {
			sc++;
			pn += WA[i];
		}
	}
	cout << sc << ' ' << pn << endl;
	return 0;
	*/
	//B
	/*int n, k, m;
	cin >> n >> k >> m;
	int sum = 0, a, i;
	for (i = 0; i < n - 1; i++) {
		cin >> a;
		sum += a;
	}
	for (i = 0; i <= k; i++) {
		if (sum + i >= n * m) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
*/	
	
	
	
	//A

	/*char c;
	cin >> c;
	cout << (char)(c + 1) << endl;
	return 0;*/
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:25: error: 'memset' was not declared in this scope
   23 |                         memset(p, -1, sizeof(p));
      |                         ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include<queue>
  +++ |+#include <cstring>
    3 | using namespace std;