luogu#P4455. [CQOI2018] 社交网络
[CQOI2018] 社交网络
Background
In today's society, checking friends' posts on social networks has become part of many people's lives. Usually, after a user posts a message on a social network, their friends can also see it and may forward it. The forwarded message can continue to be forwarded, spreading through the entire social network.
Problem Description
In a small experimental social network, we found that sometimes a popular message is eventually forwarded by everyone. To study how this happens, we want to compute how many possible forwarding paths there are for a single message. For convenience, we number the initial sender as user , and number the other users in increasing order.
All friend relations on this social network are known. That is, for two users and , we know that user can see messages sent by user . Note that one-way friend relations may exist; that is, can see 's messages, but cannot see 's.
Another assumption is that if a user sees that multiple friends forwarded the same message, they will choose exactly one of them to forward from, and will forward at most once. Forwarding from different friends is considered different cases.
If we use arrows to represent friend relations, the figures below show all possible forwarding situations in a certain social network. (The initial message is sent by user , and bold arrows indicate a single forwarding.)

Output the answer modulo .
Input Format
The first line contains an integer , the number of users.
The second line contains an integer , the number of friend relations.
Each of the next lines contains two integers , indicating a friend relation, i.e., user can see messages sent by user .
Output Format
Output a single line with one integer: the answer modulo .
4
7
2 1
3 1
1 3
2 3
3 2
4 3
4 2
6
Hint
Constraints:
- For of the testdata, .
- For of the testdata, , , .
Translated by ChatGPT 5