#icpc2013autumnd. [icpc2013autumn_d]Everlasting -One-
[icpc2013autumn_d]Everlasting -One-
MathJax.Hub.Config({ tex2jax: { inlineMath: [[""], ["\\(","\\)"]], processEscapes: true }}); blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 12px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }
Problem Statement
"Everlasting -One-" is an award-winning online game launched this year. This game has rapidly become famous for its large number of characters you can play.
In this game, a character is characterized by attributes. There are attributes in this game, numbered through . Each attribute takes one of the two states, light or darkness. It means there are kinds of characters in this game.
You can change your character by job change. Although this is the only way to change your character's attributes, it is allowed to change jobs as many times as you want.
The rule of job change is a bit complex. It is possible to change a character from to if and only if there exist two attributes and such that they satisfy the following four conditions:
-
The state of attribute of character is light.
-
The state of attribute of character is light.
-
There exists no attribute such that both characters and have the light state of attribute .
-
A pair of attribute is compatible.
Here, we say a pair of attribute is compatible if there exists a sequence of attributes satisfying the following three conditions:
-
.
-
.
-
Either or is a special pair for all . You will be given the list of special pairs.
Since you love this game with enthusiasm, you are trying to play the game with all characters (it's really crazy). However, you have immediately noticed that one character can be changed to a limited set of characters with this game's job change rule. We say character and are essentially different if you cannot change character into character by repeating job changes.
Then, the following natural question arises; how many essentially different characters are there? Since the output may be very large, you should calculate the answer modulo .
Input
The input is a sequence of datasets. The number of datasets is not more than and the total size of input is less than MB.
Each dataset is formatted as follows.
:
:
The first line of each dataset contains two integers and ( and ). Then lines follow. The -th line contains two integers and () which denote the -th special pair. The input is terminated by two zeroes.
It is guaranteed that if .
Output
For each dataset, output the number of essentially different characters modulo .
Sample Input
3 2
1 2
2 3
5 0
100000 0
0 0```
### Output for the Sample Input
```plain
3
32
607723520```
* * *
### Source Name
[JAG Practice Contest for ACM-ICPC Asia Regional 2013](http://acm-icpc.aitea.net/index.php?2013%2FPractice%2F%CC%CF%B5%BC%C3%CF%B6%E8%CD%BD%C1%AA)
* * *