Language: C++

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int h, w;
int blacks = 0;
vector<string> a;
vector<pair<int,int>> rec;
vector<pair<int, int>> st;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
void bfs(int y, int x)
{
    for (ll i = 0; i < 4; i++)
    {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (nx < 0 || ny < 0 || ny >= h || nx >= w || a[ny][nx] == '#')
            continue;
        else
        {
            a[ny][nx] = '#';
            blacks++;
            rec.emplace_back(make_pair(ny,nx));
            //st.insert(make_pair(ny, nx));
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cin >> h >> w;
    for (int i = 0; i < h; i++)
    {
        string c;
        cin >> c;
        a.emplace_back(c);
    }

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (a[i][j] == '#')
            {
                blacks++;
                st.emplace_back(make_pair(i, j));
            }
        }
    }
    int cnt = 0;
    while (blacks != h * w)
    {
        rec.resize(0);
        for (auto v : st)
        {
            bfs(v[i].first, v[i].second);
        }
        cnt++;
        st.resize(0);
        for(int i = 0; i < rec.size(); i++)
            st.insert(make_pair(rec[i].first,rec[i].second));
    }
    cout << cnt << "\n";
}

Compiler output:
a.cc: In function 'int main()':
a.cc:60:19: error: 'i' was not declared in this scope
   60 |             bfs(v[i].first, v[i].second);
      |                   ^
a.cc:65:22: error: no matching function for call to 'std::vector<std::pair<int, int> >::insert(std::pair<int, int>)'
   65 |             st.insert(make_pair(rec[i].first,rec[i].second));
      |             ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_vector.h:1484:9: note: candidate: 'template<class _InputIterator, class> std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(const_iterator, _InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >]'
 1484 |         insert(const_iterator __position, _InputIterator __first,
      |         ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:1484:9: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/vector:72:
/usr/include/c++/14/bits/vector.tcc:133:5: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(const_iterator, const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; iterator = std::vector<std::pair<int, int> >::iterator; const_iterator = std::vector<std::pair<int, int> >::const_iterator; value_type = std::pair<int, int>]'
  133 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:133:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_vector.h:1395:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(const_iterator, value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; iterator = std::vector<std::pair<int, int> >::iterator; const_iterator = std::vector<std::pair<int, int> >::const_iterator; value_type = std::pair<int, int>]'
 1395 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:1395:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_vector.h:1413:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(const_iterator, std::initializer_list<_Tp>) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; iterator = std::vector<std::pair<int, int> >::iterator; const_iterator = std::vector<std::pair<int, int> >::const_iterator]'
 1413 |       insert(const_iterator __position, initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:1413:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_vector.h:1439:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(const_iterator, size_type, const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; iterator = std::vector<std::pair<int, int> >::iterator; const_iterator = std::vector<std::pair<int, int> >::const_iterator; size_type = long unsigned int; value_type = std::pair<int, int>]'
 1439 |       insert(const_iterator __position, size_type __n, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:1439:7: note:   candidate expects 3 arguments, 1 provided