Remodeling the Dungeon 2

시간 제한8초메모리 제한2048 MB

요약
연결된 격자 그래프인 던전에서 문을 막아 방 사이의 경로가 유일하도록 만들고, 문이 하나뿐인 두 방 사이의 거리가 짝수가 되도록 남은 문을 출력한다. 불가능하면 No를 출력한다.
난이도

어려움10점 중 8점

유형
그래프, 트리, DFS, 구현
정답자
아직 제출이 없습니다

문제

The Queen of the Kingdom of Icpca resides in a castle peacefully. One day, she decided to remodel the dungeon of the castle.

The dungeon is a rectangular grid consisting of square cells. Some cells are enterable rooms, while others are duct spaces which are not enterable. All pairs of adjacent cells are separated by a wall. Some of the walls between two adjacent rooms are installed with a door to go back and forth. Any pair of rooms in the dungeon has connecting paths through these doors.

The Queen wants to remodel the dungeon so that there is only one unique path between any pair of rooms. Additionally, any pair of rooms both with only one door should be connected with a path going through an even number of doors. Due to the cost limitation, what can be done in the remodeling is only to block some (possibly zero) doors.

Your mission is to find a way to remodel the dungeon as the Queen wants.

입력

The input consists of a single test case in the following format.

hh ww

c_1,1c_1,2⋯c_1,2w+1c\_{1,1}c\_{1,2} \cdots c\_{1,2w+1}

c_2,1c_2,2⋯c_2,2w+1c\_{2,1}c\_{2,2} \cdots c\_{2,2w+1}

⋮\vdots

c_2h+1,1c_2h+1,2⋯c_2h+1,2w+1c\_{2h+1,1}c\_{2h+1,2} \cdots c\_{2h+1,2w+1}

Two integers hh and ww mean that the dungeon size is h×wh \times w. They are between 11 and 400400, inclusive.

Each of the characters c_i,jc\_{i,j} (1≤i≤2h+11 ≤ i ≤ 2h + 1, 1≤j≤2w+11 ≤ j ≤ 2w + 1) is either ‘.’ or ‘#’. These characters represent the configuration of the dungeon as follows.

  • When both ii and jj are even, c_i,jc\_{i,j} represents the cell located at the i/2i/2-th row from the north and the j/2j/2-th column from the west of the dungeon, referred to as cell (i/2,j/2)(i/2, j/2). Being ‘.’ indicates that the cell is a room, while ‘#’ indicates a duct space.
  • When ii is odd and jj is even, it represents a wall. When i=1i = 1 or i=2h+1i = 2h+ 1, it is a part of the outer wall of the dungeon. In this case, c_i,jc\_{i,j} is always ‘#’. Otherwise, c_i,jc\_{i,j} represents the wall between cells ((i−1)/2,j/2)((i - 1)/2, j/2) and ((i+1)/2,j/2)((i + 1)/2, j/2). Being ‘.’ indicates that the wall has a door, while ‘#’ indicates that it does not. Doors are installed only in walls between two rooms.
  • When ii is even and jj is odd, it also represents a wall. When j=1j = 1 or j=2w+1j = 2w + 1, it is a part of the outer wall of the dungeon. In this case, c_i,jc\_{i,j} is always ‘#’. Otherwise, c_i,jc\_{i,j} represents the wall between cells (i/2,(j−1)/2)(i/2,(j - 1)/2) and (i/2,(j+1)/2)(i/2,(j + 1)/2). Being ‘.’ indicates that the wall has a door, while ‘#’ indicates that it does not. Doors are installed only in walls between two rooms.
  • When both ii and jj are odd, c_i,jc\_{i,j} is always ‘#’, corresponding to an intersection of walls.

It is guaranteed that there is at least one room in the dungeon and any pair of rooms in the dungeon has one or more connecting paths.

출력

If it is impossible to remodel the dungeon as the Queen wants, output No. Otherwise, output Yes on the first line, followed by the configuration of the dungeon after the remodeling in the same format as the input. If there are multiple possible configurations, any one of them is acceptable.

예제3

  1. 예제 1

    입력
    3 3
    #######
    #.....#
    #.#.###
    #.#...#
    #.#.#.#
    #.....#
    #######
    
    예상 출력
    Yes
    #######
    #.....#
    #.#####
    #.#...#
    #.###.#
    #.....#
    #######
    
  2. 예제 2

    입력
    3 3
    #######
    #.....#
    ###.###
    ###...#
    ###.#.#
    #.....#
    #######
    
    예상 출력
    Yes
    #######
    #.....#
    ###.###
    ###...#
    #####.#
    #.....#
    #######
    
  3. 예제 3

    입력
    3 3
    #######
    #.....#
    #.###.#
    #.###.#
    #.###.#
    #.....#
    #######
    
    예상 출력
    No