#P3877. [TJOI2010] 打扫房间

[TJOI2010] 打扫房间

Description

A new batch of dormitories has been built at the school, and the student on duty, Xiao A, needs to clean all empty rooms. The layout of these dormitories is unusual: all rooms in the building form an N×MN \times M grid. Each room has a door on each of its north, south, east, and west walls leading to the adjacent room. Some rooms are used for storage and do not need to be cleaned. Xiao A wants to design several cleaning routes such that each room that needs cleaning is entered and exited exactly once, and the same door must not be used to both enter and leave that room. Each route must be a closed cycle, and each route must pass through more than 2 rooms.

As shown in the two figures below, both are valid cleaning plans (gray cells are rooms used for storage):

Xiao A finds that for certain layouts, no plan satisfying the requirements exists. He asks you to write a program to determine, for a given room layout, whether a valid plan exists.

Input Format

The first line contains an integer TT (1T101 \le T \le 10), indicating that there are TT groups of testdata in the file. Then follow the descriptions of the TT groups of testdata. For each group, the first line contains two integers NN and MM. The next NN lines each contain MM characters describing a room layout. A '.' means the room needs cleaning; a '#' means the room is used for storage and does not need cleaning.

Output Format

Output TT lines. For each group, output one line, either "YES" or "NO", indicating whether such a cleaning plan exists.

4
3 4
##..
....
....
3 4
##..
....
#...
3 4
##..
#...
#...
3 4
####
#..#
####

YES
NO
YES
NO

Hint

  • For 50% of the testdata, 3N,M123 \le N, M \le 12.
  • For 100% of the testdata, 3N,M303 \le N, M \le 30.
  • Time limit per test point: 1 second.

Translated by ChatGPT 5