#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
int n, m, X, Y, ans;
char g[4005][4005];
bool u[4005][4005];
queue<pii> t[2], q[2];
void dfs(int X, int Y){
if (X<1 || Y<1 || X>n || Y>m) return;
//cout << X << ' ' << Y << endl;
if (u[X][Y] || g[X][Y]=='.') return;
u[X][Y]=1;
if (g[X-1][Y]=='.' || g[X+1][Y]=='.' || g[X][Y-1]=='.' || g[X][Y+1]=='.')
t[g[X][Y]=='F'].push(mp(X, Y));
dfs(X-1, Y);
dfs(X+1, Y);
dfs(X, Y-1);
dfs(X, Y+1);
}
int bfs(bool T, bool F){
if (F){
memset(u, 0, sizeof u2);
q[0]=t[0];
q[1]=t[1];
}
bool k=0;
if (q[0].empty() && q[1].empty()) return 0;
while(!q[T].empty()){
X=q[T].front().x; Y=q[T].front().y; q[T].pop();
if (X<1 || Y<1 || X>n || Y>m) continue;
if (u[X][Y] || g[X][Y]=='.') continue;
u[X][Y]=1;
k=1;
q[g[X+1][Y]=='F'].push(mp(X+1, Y));
q[g[X-1][Y]=='F'].push(mp(X-1, Y));
q[g[X][Y+1]=='F'].push(mp(X, Y+1));
q[g[X][Y-1]=='F'].push(mp(X, Y-1));
}
return bfs(!T, 0)+k;
}
int main(){
cin.sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
fox1(l, n){
fox1(l2, m){
cin >> g[l][l2];
}
}
dfs(1, 1);
//cout << t[0].size() << ' ' << t[1].size() << endl;
//cout << bfs(1, 1) << ' ' << bfs(0, 1) << endl;
ans+=min(bfs(0, 1), bfs(1, 1));
cout << ans << endl;
return 0;
}
Compilation message
tracks.cpp: In function 'int bfs(bool, bool)':
tracks.cpp:44:29: error: 'u2' was not declared in this scope
memset(u, 0, sizeof u2);
^