#include #include #include using namespace std; typedef long long ll; #define rep(i,a,n) for(int i=(a);i<(n);i++) //Union-Find struct UnionFind{ vector par, rank, siz; UnionFind(int n) : par(n, -1), rank(n, 0), siz(n, 1) {} int root(int x){ if(par[x] == -1) return x; else return par[x] = root(par[x]); } bool same(int x, int y){ return root(x) == root(y); } bool unite(int x, int y){ int rx = root(x), ry = root(y); if(rx == ry) return false; if(rank[rx] < rank[ry]) swap(rx, ry); par[ry] = rx; if(rank[rx] == rank[ry]) rank[rx]++; siz[rx] += siz[ry]; return true; } int size(int x) { return siz[root(x)]; } vector> group(){ vector> tmp(par.size()); for(int i = 0; i < (int)par.size(); i++) tmp[root(i)].push_back(i); vector> ans; for(vector p : tmp) if(!p.empty()) ans.push_back(p); return ans; } }; int h, w; string g[1000]; int d[5] = {0, 1, 0, -1, 0}; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> h >> w; UnionFind uf(h*w); for(int i=0; i> g[i]; for(int i=0; i v : uf.group()){ if(v.size()<4) continue; for(int p : v) g[p/w][p%w] = '.'; } for(int i=0; i