#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 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 (), indicating that there are groups of testdata in the file. Then follow the descriptions of the groups of testdata. For each group, the first line contains two integers and . The next lines each contain 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 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, .
- For 100% of the testdata, .
- Time limit per test point: 1 second.
Translated by ChatGPT 5
京公网安备 11011102002149号