#P2691. 逃离

逃离

Description

Translated from CLRS Problem 26-1: Escape problem.

In an n×nn \times n grid, there are mm starting points (x1,y1)(x_1, y_1), (x2,y2)(x_2, y_2), \dots, (xm,ym)(x_m, y_m). Determine whether it is possible to find a path for each starting point to the boundary such that these mm paths are pairwise disjoint (that is, no two paths share any point).

https://i.loli.net/2018/10/14/5bc2ec2948f8b.png

Black dots indicate starting points, and other points are white. The found paths are shown with bold lines. In figure (a), there exist mm valid paths; in figure (b), there do not.

Input Format

The first line contains an integer nn (1n351 \le n \le 35).

The second line contains an integer mm (1mn21 \le m \le n^2).

Each of the following mm lines, the (i+2)(i + 2)-th line, contains two integers xix_i and yiy_i, meaning that the point at row xix_i, column yiy_i is a starting point. The starting points are guaranteed to be distinct.

Output Format

Output a single line. If an escape exists, output YES; otherwise, output NO.

6
10
2 2
2 4
2 6
3 1
3 2
3 4
3 6
4 2
4 4
4 6

YES

Hint

Translated by ChatGPT 5