Anti-cyclic grids

5

3 votes
Graphs, Algorithms, Depth First Search
Problem

You are given a grid with n rows and m columns where all cells are either empty or full. Two cells are connected if they both are empty and share a side in the grid.

Fill at most Number of empty cells3 empty cells that the resulting grid does not contain any simple cycle.

Input format

  • The first line contains two space-separated integers n and m.
  • The grid is given in next n lines. Each line contains a m-length string which is made of '.'s (empty cell) and '#'s (full cell).
    1n,m100

Output format

Print the result grid in the described format. If there are several answers, then print any answers.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The resulting grid does not contain any simple cycle. there are lots of other answers for this test case.

Editor Image

?