unionFind u('m',1d6,1); ll@h,@w; string@g[h]; rep(y,h){ rep(x,w){ if(y&&g[y-1][x]==g[y][x])u(y*w+x,(y-1)*w+x); if(x&&g[y][x-1]==g[y][x])u(y*w+x,y*w+(x-1)); } } rep(y,h){ rep(x,w){ wtN(u.size(y*w+x)<4?g[y][x]:'.'); } wt(""); }