Sister Ports
Time limit8sMemory limit512 MB
Count the perfect matchings of a planar graph formed by a convex polygon's boundary plus non-crossing chords, modulo 1000003.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Geometry, Combinatorics, Divide and conquer
- Solved
- No attempts yet
Problem
ACM is an island nation in the shape of a regular -gon. There are ports at the vertices, numbered 1 to clockwise starting from one vertex. Ports are treated as points.
ACM has two kinds of roads.
- Roads connecting adjacent ports Every pair of adjacent ports is connected by a road. That is, there is a road between ports whose numbers differ by 1, and between port 1 and port . There are roads of this kind.
- Roads passing through the interior of the island Some pairs of non-adjacent ports are also connected by roads. There are roads of this kind, and road connects port and port .
Roads are treated as line segments. In ACM, no two roads share a point other than an endpoint.

Figure G-1: An example of ports and roads
To prepare for accidents at ports, ACM decided to assign a sister port to every port so that any two ports can help each other at any time. Every port has exactly one sister port, and if port is the sister port of port , then port is also the sister port of port . That is, the ports are divided into pairs of distinct ports. ACM further decided that there must be a road between sister ports.
Your job, as an excellent programmer living in ACM, is to write a program that computes the total number of ways to assign sister ports to all ports.

Figure G-2: Examples of assignments of sister ports (roads between sister ports are shown as thick red lines)
Input
The input consists of one or more data sets. Each data set has the following format.
n m
a1 b1
...
am bm
The first line contains two positive integers and , which are the number of ports in ACM and the number of roads of kind 2. The -th of the following lines contains two integers and , meaning that road connects ports and .
No two roads share a point other than an endpoint. The numbers have the following ranges.
The end of the input is marked by a line containing two zeros.
Output
For each data set, output the total number of ways to assign sister ports modulo . If no valid assignment of sister ports exists, output 0.