Language: C++

#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

// ------ Class ------ //
class Graph1 {
public:
	// ------ Variables ------ //
	static const int INF = 1000000000;
	int V, E; vector<vector<int> > G;

	// ------ Constructors ------ //
	Graph1() : V(0), E(0), G(vector<vector<int> >()) {}
	Graph1(int v) : V(v), E(0), G(vector<vector<int> >(v)) {}
	Graph1(vector<vector<int> > g) : V(g.size()), G(g) { for (int i = 0; i < g.size(); i++) E += g[i].size(); }

	// ------ Basic Functions ------ //
	int size() { return V; }
	void add1(int v1, int v2) { G[v1].push_back(v2); E++; }
	void add2(int v1, int v2) { add1(v1, v2); add1(v2, v1); }

	// ------ Operators ------ //
	friend bool operator==(const Graph1& g1, const Graph1& g2) { return g1.G == g2.G; }
	friend bool operator!=(const Graph1& g1, const Graph1& g2) { return g1.G != g2.G; }
	vector<int> operator[](int x) { return G[x]; }

	// ------ Algorithms ------ //
	vector<int> dist(int s) {
		queue<int> que; que.push(s);
		vector<int> d(V, INF); d[s] = 0;
		while (!que.empty()) {
			int u = que.front(); que.pop();
			for (int i = 0; i < G[u].size(); i++) {
				if (d[G[u][i]] == INF) {
					d[G[u][i]] = d[u] + 1;
					que.push(G[u][i]);
				}
			}
		}
		return d;
	}
};

// ------ Main ------ //
int H, W, x[91][91];
int main() {
	while(cin >> W >> H, W) {
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) cin >> x[i][j];
		}
		Graph1 G(H * W);
		for(int i = 1; i < H; i++) {
			for(int j = 0; j < W; j++) {
				int v = i * W + j;
				if(x[i - 1][j] && x[i][j]) G.add2(v, v - W);
			}
		}
		for(int i = 0; i < H; i++) {
			for(int j = 1; j < W; j++) {
				int v = i * W + j;
				if(x[i][j - 1] && x[i][j]) G.add2(v, v - 1);
			}
		}
		int ret = 0;
		for(int i = 0; i < H * W; i++) vector<int> v = G.dist(i), ret = max(ret, *max_element(v.begin(), v.end()));
		cout << ret << endl;
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:67:84: error: no matching function for call to 'max(std::vector<int>&, int&)'
   67 |                 for(int i = 0; i < H * W; i++) vector<int> v = G.dist(i), ret = max(ret, *max_element(v.begin(), v.end()));
      |                                                                                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/deque:62,
                 from /usr/include/c++/14/queue:62,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:67:84: note:   deduced conflicting types for parameter 'const _Tp' ('std::vector<int>' and 'int')
   67 |                 for(int i = 0; i < H * W; i++) vector<int> v = G.dist(i), ret = max(ret, *max_element(v.begin(), v.end()));
      |                                                                                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:67:84: note:   'std::vector<int>' is not derived from 'std::initializer_list<_Tp>'
   67 |                 for(int i = 0; i < H * W; i++) vector<int> v = G.dist(i), ret = max(ret, *max_element(v.begin(), v.end()));
      |                                                                                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~