DMOPC '15 Contest 3 P6 - Gala

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 1.0s
PyPy 2 2.0s
PyPy 3 2.0s
Memory limit: 128M

Problem types

All the DMOJ admins have come together to organize the Don Mills Programming Gala, an event where contestants come to Don Mills C. I. and show off their programming skills! The organizers have discovered that, this year, everybody is competing in a pair. To help organize the Gala, Xyene will draw a diagram of which contestants are partners.

On Xyene's diagram, there are N dots on a line representing the contestants, which have been numbered from 1 on the left to N on the right. No two points are on top of each other, and N is always even. Xyene can use a compass to connect pairs of dots in the diagram by drawing a perfect semicircle which begins at one dot and ends at another. These semicircles can only be drawn strictly above the line of points.

k_53P drew K semicircles in red ink such that no two intersect. Xyene is able to erase any subset of the semicircles drawn in red, but he is only able to draw new semicircles in gray.

What is the number of distinct ways to complete Xyene's diagram? We will consider the diagram complete only if there are \frac N2 semicircles drawn, every point has been connected to a different point, and no two semicircles intersect with each other. Two ways are considered distinct if two points are connected in one way while they are not in the other, or if two points are connected with the colour red in one way while they are connected with gray in the other.

Since your answer may be extremely large, output it modulo 1\,000\,000\,007.


For all cases,

N, K \ge 0

N is an even number.

No two semicircles initially given will intersect with each other.

Subtask 1 [5%]

N \le 10, K = 0

Subtask 2 [5%]

N \le 10, K = 1

Subtask 3 [10%]

N \le 400, K \le 2

Subtask 4 [20%]

N \le 400, K \le 18

Subtask 5 [20%]

N \le 400, K \le 53

Subtask 6 [30%]

N \le 1100, K \le 53

Subtask 7 [10%]

N \le 4000, K \le 1500

Note: PyPy 2 and PyPy 3 both have a time limit of 2 seconds.

Input Specification

The first line will contain a single integer, N.

The following line will contain a single integer, K.

The following K lines will each contain two space-separated integers, a and b, where 1 \le a < b \le N and (a,b) represents a red semicircle which connects point a to point b. It is guaranteed that all values of a and b will be distinct, and that no two semi-circles will intersect.

Output Specification

Output a single integer, the number of ways to complete the diagram modulo 1\,000\,000\,007 (10^9+7).

Sample Input 1

1 6

Sample Output 1


Explanation for Sample 1

There are six points on the line, with one semicircle already drawn from point 1 (the leftmost point) to point 6 (the rightmost point). If we do not erase this initial semicircle, then there are two ways to complete the diagram. If we do erase it, then there are five ways.

Sample Input 2

1 3

Sample Output 2


Explanation for Sample 2

There is no way to complete the diagram if we do not erase the part already drawn. Points 2 and 4 cannot be connected without intersecting with the connection between 1 and 3. Therefore, we must erase the initially drawn semicircle, and this creates 2 ways to complete the diagram.

Sample Input 3

1 2
3 4

Sample Output 3


Explanation for Sample 3

There are four cases: erase nothing for 1 way to complete the diagram, erase only the left semicircle (1,2) for 2 ways, erase only the right semicircle (3,4) for 2 ways, or erase them both for 5 ways. This results in 1+2+2+5=10 ways.

Sample Input 4


Sample Output 4



There are no comments at the moment.