Language: C++

#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h + 2);
    s[0] = string(w + 2, '#');
    s[h + 1] = string(w + 2, '#');
    string t;
    REP1(i, h) {
        cin >> t;
        s[i] = '#' + t + '#';
    }

    int ans = 0;
    REP1(i, h) REP1(j, w) {
        if (s[i][j] == '#') continue;
        REP1(k, h) REP1(l, w) {
            if (s[k][l] == '#') continue;
            // cout << "---------" << EOL; cout << i << ":" << j << "//" << k << ":" << l << EOL;

            deque<pair<pair<int, int>, int>> q;
            q.emplace_back(i, j, 0);
            set<pair<int, int>> memo;
            memo.emplace(i, j);
            int r, c, t;
            while (!q.empty()) {
                tie(r, c, t) = q.front(); q.pop_front();
                // cout << r << ":" << c << "/" << t << EOL;

                if (r == k && c == l) {
                    chmax(ans, t);
                    break;
                }

                auto p = make_pair(r - 1, c);
                if (s[r - 1][c] != '#' && memo.count(p) == 0) {
                    memo.emplace(p);
                    q.emplace_back(p, t + 1);
                }
                p = make_pair(r + 1, c);
                if (s[r + 1][c] != '#' && memo.count(p) == 0) {
                    memo.emplace(p);
                    q.emplace_back(p, t + 1);
                }
                p = make_pair(r, c - 1);
                if (s[r][c - 1] != '#' && memo.count(p) == 0) {
                    memo.emplace(p);
                    q.emplace_back(p, t + 1);
                }
                p = make_pair(r, c + 1);
                if (c != w - 1 && s[r][c + 1] != '#' && memo.count(p) == 0) {
                    memo.emplace(p);
                    q.emplace_back(p, t + 1);
                }
            }
        }
    }
    cout << ans << EOL;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:56:40: error: no match for 'operator=' (operand types are 'std::tuple<int&, int&, int&>' and '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::pair<int, int>, int> >, std::pair<std::pair<int, int>, int> >::value_type' {aka 'std::pair<std::pair<int, int>, int>'})
   56 |                 tie(r, c, t) = q.front(); q.pop_front();
      |                                        ^
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/tuple:1930:9: note: candidate: 'template<class ... _UElements> std::__enable_if_t<((bool)__assignable<const _UElements& ...>()), std::tuple< <template-parameter-1-1> >&> std::tuple< <template-parameter-1-1> >::operator=(const std::tuple<_Args1 ...>&) [with _UElements = {_UElements ...}; _Elements = {int&, int&, int&}]'
 1930 |         operator=(const tuple<_UElements...>& __in)
      |         ^~~~~~~~
/usr/include/c++/14/tuple:1930:9: note:   template argument deduction/substitution failed:
a.cc:56:40: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::pair<int, int>, int> >, std::pair<std::pair<int, int>, int> >::value_type' {aka 'std::pair<std::pair<int, int>, int>'} is not derived from 'const std::tuple<_UTypes ...>'
   56 |                 tie(r, c, t) = q.front(); q.pop_front();
      |                                        ^
/usr/include/c++/14/tuple:1940:9: note: candidate: 'template<class ... _UElements> std::__enable_if_t<((bool)__assignable<_UElements ...>()), std::tuple< <template-parameter-1-1> >&> std::tuple< <template-parameter-1-1> >::operator=(std::tuple<_Args1 ...>&&) [with _UElements = {_UElements ...}; _Elements = {int&, int&, int&}]'
 1940 |         operator=(tuple<_UElements...>&& __in)
      |         ^~~~~~~~
/usr/include/c++/14/tuple:1940:9: note:   template argument deduction/substitution failed:
a.cc:56:40: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::pair<int, int>, int> >, std::pair<std::pair<int, int>, int> >::value_type' {aka 'std::pair<std::pair<int, int>, int>'} is not derived from 'std::tuple<_UTypes ...>'
   56 |                 tie(r, c, t) = q.front(); q.pop_front();
      |                                        ^
/usr/include/c++/14/tuple:1907:7: note: candidate: 'std::tuple< <template-parameter-1-1> >& std::tuple< <template-parameter-1-1> >::operator=(std::__conditional_t<((bool)__assignable<const _Elements& ...>()), const std::tuple< <template-parameter-1-1> >&, const std::__nonesuch&>) [with _Elements = {int&, int&, int&}; std::__conditional_t<((bool)__assignable<const _Elements& ...>()), const std::tuple< <template-parameter-1-1> >&, const std::__nonesuch&> = const std::tuple<int&, int&, int&>&]'
 1907 |       operator=(__conditional_t<__assignable<const _Elements&...>(),
      |       ^~~~~~~~
/usr/include/c++/14/tuple:1909:52: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::pair<int, int>, int> >, std::pair<std::pair<int, int>, int> >::value_type' {aka 'std::pair<std::pair<int, int>, int>'} to 'std::__conditional_t<true, const std::tuple<int&, int&, int&>&, const std::__nonesuch&>' {aka 'const std::tuple<int&, int&, int&>&'}
 1907 |       operator=(__conditional_t<__assignable<const _Elements&...>(),
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1908 |                                 const tuple&,
      |                                 ~~~~~~~~~~~~~       
 1909 |                                 const __nonesuch&> __in)
      |                                 ~~~~~~~~~~~~~~~~~~~^~~~
/usr/include/c++/14/tuple:1918:7: note: candidate: 'std::tuple< <template-parameter-1-1> >& std::tuple< <template-parameter-1-1> >::operator=(std::__conditional_t<((bool)__assignable<_Elements ...>()), std::tuple< <template-parameter-1-1> >&&, std::__nonesuch&&>) [with _Elements = {int&, int&, int&}; std::__conditional_t<((bool)__assignable<_Elements ...>()), std::tuple< <template-parameter-1-1> >&&, std::__nonesuch&&> = std::tuple<int&, int&, int&>&&]'
 1918 |       operator=(__conditional_t<__assignable<_Elements...>(),
      |       ^~~~~~~~
/usr/include/c++/14/tuple:1920:47: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::pair<int, int>, int> >, std::pair<std::pair<int, int>, int> >::value_type' {aka 'std::pair<std::pair<int, int>, int>'} to 'std::__conditional_t<true, std::tuple<int&, int&, int&>&&, std::__nonesuch&&>' {aka 'std::tuple<int&, int&, int&>&&'}
 1918 |       operator=(__conditional_t<__assignable<_Elements...>(),
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1919 |                                 tuple&&,
      |                                 ~~~~~~~~       
 1920 |                                 __nonesuch&&> __in)
      |                                 ~~~~~~~~~~~~~~^~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/c++allocator.h:33,
                 from /usr/include/c++/14/bits/allocator.h:46,
                 from /usr/include/c++/14/string:43:
/usr/include/c++/14/bits/new_allocator.h: In instantiation of 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::pair<std::pair<int, int>, int>; _Args = {int&, int&, int}; _Tp = std::pair<std::pair<int, int>, int>]':
/usr/include/c++/14/bits/alloc_traits.h:575:17:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = std::pair<std::pair<int, int>, int>; _Args = {int&, int&, int}; _Tp = std::pair<std::pair<int, int>, int>; allocator_type = std::allocator<std::pair<std::pair<int, int>, int> >]'
  575 |           __a.construct(__p, std::forward<_Args>(__args)...);
      |           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/deque.tcc:170:30:   required from 'std::deque<_Tp, _Alloc>::reference std::deque<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {int&, int&, int}; _Tp = std::pair<std::pair<int, int>, int>; _Alloc = std::allocator<std::pair<std::pair<int, int>, int> >; reference = std::pair<std::pair<int, int>, int>&]'
  170 |             _Alloc_traits::construct(this->_M_impl,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
  171 |                                      this->_M_impl._M_finish._M_cur,
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  172 |                                      std::forward<_Args>(__args)...);
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:51:27:   required from here
   51 |             q.emplace_back(i, j, 0);
      |             ~~~~~~~~~~~~~~^~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:191:11: error: no matching function for call to 'std::pair<std::pair<int, int>, int>::pair(int&, int&, int)'
  191 |         { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_pair.h:913:28: note: candidate: 'template<class _U1, class _U2, typename std::enable_if<(std::_PCC<((! std::is_same<std::pair<int, int>, _U1>::value) || (! std::is_same<int, _U2>::value)), std::pair<int, int>, int>::_MoveConstructiblePair<_U1, _U2>() && (! std::_PCC<((! std::is_same<std::pair<int, int>, _U1>::value) || (! std::is_same<int, _U2>::value)), std::pair<int, int>, int>::_ImplicitlyMoveConvertiblePair<_U1, _U2>())), bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(std::pair<_U1, _U2>&&) [with _U2 = _U1; typename std::enable_if<(std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && (! std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>())), bool>::type <anonymous> = _U2; _T1 = std::pair<int, int>; _T2 = int]'
  913 |         explicit constexpr pair(pair<_U1, _U2>&& __p)
      |                            ^~~~
/usr/include/c++/14/bits/stl_pair.h:913:28: note:   candidate expects 1 argument, 3 provided
/usr/include/c++/14/bits/stl_pair.h:902:19: note: candidate: 'template<class _U1, class _U2, typename std::enable_if<(std::_PCC<((! std::is_same<std::pair<int, int>, _U1>::value) || (! std::is_same<int, _U2>::value)), std::pair<int, int>, int>::_MoveConstructiblePair<_U1, _U2>() && std::_PCC<((! std::is_same<std::pair<int, int>, _U1>::value) || (! std::is_same<int, _U2>::value)), std::pair<int, int>, int>::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(std::pair<_U1, _U2>&&) [with _U2 = _U1; typename std::enable_if<(std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> = _U2; _T1 = std::pair<int, int>; _T2 = int]'
  902 |         constexpr pair(pair<_U1, _U2>&& __p)
      |                   ^~~~
/usr/include/c++/14/bits/stl_pair.h:902:19: note:   candidate expects 1 argument, 3 provided
/usr/include/c++/14/bits/stl_pair.h:891:28: note: candidate: 'template<class _U1, class _U2, typename std::enable_if<(_MoveConstructiblePair<_U1, _U2>() && (! _ImplicitlyMoveConvertiblePair<_U1, _U2>())), bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(_U1&&, _U2&&) [with _U2 = _U1; typename std::enable_if<(std::_PCC<true, _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && (! std::_PCC<true, _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>())), bool>::type <anonymous> = _U2; _T1 = std::pair<int, int>; _T2 = int]'
  891 |         expl