QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 256 MB Total points: 100 Difficulty: [show]

#7. Main Theme

الإحصائيات

Responding to the call of the main theme, everyone decided to fill the class with love. Now there are $n$ boys in the class.

If $a$ loves $b$, then this is equivalent to having a directed edge $a \to b$ between them. If the directed graph formed by these $n$ nodes is strongly connected, then the class is considered to be full of love.

Unfortunately, some bad things happened, and now every edge may be destroyed. As a messenger of love, I want to know in how many different ways edges can be destroyed such that the class is still full of love.

(In plain words: how many subsets of edges can be deleted so that the entire graph remains strongly connected?)

Input Format

The first line contains two integers $n$ and $m$, representing the number of boys in the class and the number of love relationships.

The next $m$ lines each contain two integers $a$ and $b$, meaning that boy $a$ loves boy $b$. It is guaranteed that $a \ne b$.

All boys are numbered from $1$ to $n$.

The same edge will not appear twice, but it is possible that $a$ loves $b$ and $b$ loves $a$; these are considered two different edges.

Output Format

Output a single integer, representing the answer modulo $10^9 + 7$.

Example

Example Input

5 15
4 3
4 2
2 5
2 1
1 2
5 1
3 2
4 1
1 4
5 4
3 4
5 3
2 3
1 5
3 1

Example Output

9390

Constraints

For $20%$ of the data: $n \le 5$.

For $50%$ of the data: $n \le 8$.

For $70%$ of the data: $n \le 10$.

For $100%$ of the data: $n \le 15$, $0 \le m \le n(n - 1)$.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.