穿越隧道
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef pair<int,int> pii;
const int N = 1e3 + 10, M = N * N;
char g[N][N];
bool st[N][N];
pii q[M];
int n,m;
int ans;
void dfs(int a, int b){
q[0] = {a,b};
st[a][b] = true;
int hh = 0, tt = 0;
while(hh <= tt){
pii t = q[hh++];
for(int i = t.x - 1; i <= t.x + 1; i ++){
for(int j = t.y - 1; j <= t.y + 1; j++){
if(i == t.x && j == t.y) continue;
if(g[i][j] == '.' || st[i][j]) continue;
if(i < 0 || i >= n || j < 0 || j >= m) continue;
st[i][j] = true;
q[++tt] = {i,j};
}
}
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i = 0; i < n; i++) scanf("%s",g[i]);
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(g[i][j] == 'W' && !st[i][j]){
dfs(i,j);
ans++;
}
}
}
printf("%d\n",ans);
return 0;
}










