190. Dominoes
time limit per test: 0.25
sec.
memory limit per test: 4096
KB
input: standard input
output: standard output
There is a NxN squared chessboard (1<=N<=40). P squares were removed from the chessboard (0<=P<N*N). It is necessary to find out whether it is possible to cover the remaining part of the chessboard with dominoes dice (each die is 2x1 squares sized). Each die should lie on two neighboring squares exactly. No two dice can cover one and the same square. Your task is to find the covering, if it exists.
Input
The first line contains two integer numbers N and P separated by a space. Each of the following P lines contains a pair of numbers separated by a space  coordinates of the removed square (1<=Xi, Yi<=N). The bottom left square has the coordinates (1, 1), the bottom right square  (N, 1).
Output
If the covering exists, output "Yes" to the first line and "No" in the opposite case. If the first answer was positive, then output to the second line integer number Nh  the number of horizontally placed dice. Each of the following Nh lines should contain two integers  the coordinates of the left square covered by a corresponding die. Output to the next line Nv  the number of vertically placed dice. And the following Nv lines should contain the coordinates of the bottom square covered by a corresponding die.
Sample test(s)
Input
4 10
1 3
1 2
1 1
2 1
3 1
4 1
3 2
4 2
3 3
4 3
Output
Yes
2
1 4
3 4
1
2 2
Author:  Michael R. Mirzayanov

Resource:  ACM International Collegiate Programming Contest 20032004
NorthEastern European Region, Southern Subregion

Date:  2003 October, 9

Server time: 20180620 21:05:42  Online Contester Team © 2002  2016. All rights reserved. 

