Language: C++

#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int H,W;
	cin >> H >> W;
	vector< string > org(H),fldA(H),fldB(H);
	UnionFind uf(H*W);
	vector< bool > used(H*W,false);//代表値のみuf.find()
	for(int h=0;h<H;++h){
		cin >> org[h];
		fldA[h] = org[h];
		fldB[h] = org[h];
		for(int w=0;w<W;++w){
			if( org[h][w] != '#' ) continue;
			if( org[h-1][w] == '#' ){
				uf.add((h-1)*W + w,h*W + w);
			}
			if( org[h][w-1] == '#' ){
				uf.add(h*W + (w-1),h*W + w );
			}
		}
	}
	
	
	for(int w=1;w<W-1;++w){//端でない一番上を塗る。
		fldA[1][w] = '#';
		if( w > 1 ){//左と繋ぐ
			uf.add(W + w-1,W + w);
			int num = uf.find(W+w);
			used[num] = true;
		}
		if( 2 < H ){
			if( fldA[2][w] == '#' ){//下
				uf.add(1*W + w, 2*W + w);
				int num = uf.find(1*W+w);
				used[num] = true;
			}
		}
	}
	
	for(int h=0;h<H;++h){//全面塗る。
		for(int w=0;w<W;++w){
			fldB[h][w] = '#';
		}
		if( h==1 ){
			for(int w=1;w<W-1;++w){
				if( org[h][w] != '#' ){
					fldB[h][w] = '.';//fldAで塗っている
				}
			}
		}
	}
	
	for(int h=2;h<H-1;++h){
		for(int w=1;w<W-1;++w){
			if( org[h][w] != '#' ) continue;
			int num = h*W + w;
			num = uf.find( num );
			if( used[num] ) continue;
			used[num] = true;
			for(int hh = h-1; hh>=1;--hh){
				if( org[hh][w] == '#' ) break;
				fldA[hh][w] = '#';
				fldB[hh][w] = '.';
			}
		}
	}
	for(int h=0;h<H;++h){
		cout << fldA[h] << endl;
	}
	cout << endl;
	for(int h=0;h<H;++h){
		cout << fldB[h] << endl;
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


Compiler output:
a.cc: In function 'void solve()':
a.cc:51:9: error: 'UnionFind' was not declared in this scope
   51 |         UnionFind uf(H*W);
      |         ^~~~~~~~~
a.cc:60:33: error: 'uf' was not declared in this scope
   60 |                                 uf.add((h-1)*W + w,h*W + w);
      |                                 ^~
a.cc:63:33: error: 'uf' was not declared in this scope
   63 |                                 uf.add(h*W + (w-1),h*W + w );
      |                                 ^~
a.cc:72:25: error: 'uf' was not declared in this scope
   72 |                         uf.add(W + w-1,W + w);
      |                         ^~
a.cc:78:33: error: 'uf' was not declared in this scope
   78 |                                 uf.add(1*W + w, 2*W + w);
      |                                 ^~
a.cc:102:31: error: 'uf' was not declared in this scope
  102 |                         num = uf.find( num );
      |                               ^~