| UTPC Spring 2024 Open Contest |
|---|
| Finished |
Tommy is cataloging records in her music shop. She wants to arrange them onto a 1-dimensional shelf by record matrix number, but some of the ink has been scratched off. Given $$$n$$$ disks labeled $$$1$$$ to $$$n$$$, she has deduced the following $$$k$$$ relationships: in the $$$i$$$th relationship, she knows that two disks $$$a_i$$$ and $$$b_i$$$ are adjacent to each other. It is guaranteed that each unordered pair $$$(a_i, b_i)$$$ of disks is distinct. Given these $$$k$$$ conditions, determine how many ways she can catalog the disks mod $$$10^9+7$$$.
The first line has two integers $$$n$$$ ($$$2\leq n \leq 10^5$$$) and $$$k$$$ ($$$1\leq k \leq 10^5$$$).
The next $$$k$$$ lines each contain two integers $$$a_i$$$ and $$$b_i$$$ ($$$1\leq a_i \lt b_i\leq n$$$).
Please print $$$-1$$$ if arranging the disks given the current conditions is impossible, otherwise print the number of ways Tommy can catalog the disks, modulo $$$10^9+7$$$.
7 31 32 31 2
-1
7 51 22 51 34 63 4
4
100 102 64 958 3824 5734 4635 5835 9537 6540 6053 93
764445383
In the first sample test case, there is no way to arrange the disks given the conditions.
In the second sample test case, there are four valid sequences: $$$\{5, 2, 1, 3, 4, 6, 7\}, \{7, 5, 2, 1, 3, 4, 6\}, \{6, 4, 3, 1, 2, 5, 7\}$$$, and $$$\{7, 6, 4, 3, 1, 2, 5\}$$$.
| Name |
|---|


