#include using namespace std; class UnionFind{ public: vector par,siz; void make(int N){ par.resize(N,-1); siz.resize(N,1); } int root(int x){ if(par.at(x) == -1) return x; else return par.at(x) = root(par.at(x)); } void unite(int u, int v){ u = root(u),v = root(v); if(u == v) return; if(siz.at(u) < siz.at(v)) swap(u,v); par.at(v) = u; siz.at(u) += siz.at(v); } bool issame(int u, int v){ if(root(u) == root(v)) return true; else return false; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int H,W; cin >> H >> W; vector S(H); for(auto &s : S) cin >> s; int n = H*W; UnionFind Z; Z.make(n); vector> dxy = {{-1,0},{0,1},{1,0},{0,-1}}; for(int i=0; i= H || ny >= W) continue; int pos2 = nx*W+ny; if(S.at(i).at(k) == S.at(nx).at(ny)) Z.unite(pos,pos2); } } for(int i=0; i= 4) S.at(i).at(k) = '.'; for(auto &s : S) cout << s << "\n"; }