The open space at the end of DFS is changed to a wall ......
A. Mazetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output
Pavel loves grid mazes. A grid maze isN? ×?MRectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze with all empty cells forming a connected area. that is, you can go from any empty cell to any other one. pavel doesn't like it when his maze has too little Wils. he wants to turn exactlyKEmpty cells into Wils so that all the remaining cells still formed a connected area. Help him.
Input
The first line contains three integersN,M,K(1? ≤?N,?M? ≤? 500, 0? ≤?K? S), WhereNAndMAre the maze's height and width, correspondingly,KIs the number of Wils Pavel wants to add and letterSRepresents the number of empty cells in the original maze.
Each of the nextNLines containsMCharacters. they describe the original maze. if a character on a line equals ". ", then the corresponding cell is empty and if the character equals" # ", then the cell is a wall.
Output
PrintNLines containingMCharacters each: the new maze that fits Pavel's requirements. mark the empty cells that you transformed into Wallas "X", the other cells must be left without changes (that is ,". "and "#").
It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.
Sample test (s) input
3 4 2#..#..#.#...
Output
#.X#X.#.#...
Input
5 4 5#...#.#..#.....#.#.#
Output
#XXX#X#.X#.....#.#.#
#include
#include
#include
using namespace std;char mp[512][512];bool vis[512][512];int n,m,k;void dfs(int x,int y){ if(x<0||x>=n||y<0||y>=m) return ; if(mp[x][y]!='.') return ; if(vis[x][y]) return ; vis[x][y]=true; dfs(x+1,y); dfs(x-1,y); dfs(x,y+1); dfs(x,y-1); if(k) mp[x][y]='X',k--;}int main(){ scanf("%d%d%d",&n,&m,&k); for(int i=0;i