#P4455. [CQOI2018] 社交网络

    ID: 3387 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2018重庆各省省选生成树向量构造

[CQOI2018] 社交网络

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 11, and number the other users in increasing order.

All friend relations on this social network are known. That is, for two users aa and bb, we know that user aa can see messages sent by user bb. Note that one-way friend relations may exist; that is, aa can see bb's messages, but bb cannot see aa'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 11, and bold arrows indicate a single forwarding.)

Output the answer modulo 104+710^4 + 7.

Input Format

The first line contains an integer nn, the number of users.
The second line contains an integer mm, the number of friend relations.
Each of the next mm lines contains two integers a,ba, b, indicating a friend relation, i.e., user aa can see messages sent by user bb.

Output Format

Output a single line with one integer: the answer modulo 104+710^4 + 7.

4
7
2 1
3 1
1 3
2 3
3 2
4 3
4 2

6

Hint

Constraints:

  • For 30%30\% of the testdata, n10n \leq 10.
  • For 100%100\% of the testdata, 1n2501 \leq n \leq 250, 1mn×(n1)1 \leq m \leq n \times (n - 1), 1a,bn1 \leq a, b \leq n.

Translated by ChatGPT 5