QOJ.ac

QOJ

Süre Sınırı: 2 s Bellek Sınırı: 256 MB Toplam puan: 100

#21265. Bovine Alliance

İstatistikler

Bessie and her bovine pals from nearby farms have finally decided that they are going to start connecting their farms together by trails in an effort to form an alliance against the farmers. The cows in each of the $N$ $1 \le N \le 100,000$ farms were initially instructed to build a trail to exactly one other farm, for a total of $N$ trails. However months into the project only $M$ $1 \le M < N$ of these trails had actually been built.

Arguments between the farms over which farms already built a trail now threaten to split apart the cow alliance. To ease tension, Bessie wishes to calculate how many ways the $M$ trails that exist so far could have been built. For example, if there is a trail connecting farms 3 and 4, then one possibility is that farm 3 built the trail, and the other possibility is that farm 4 built the trail. Help Bessie by calculating the number of different assignments of trails to the farms that built them, modulo 1,000,000,007. Two assignments are considered different if there is at least one trail built by a different farm in each assignment.

Input

  • Line 1: Two space-separated integers $N$ and $M$
  • Lines $2..1+M$: Line $i+1$ describes the ith trail. Each line contains two space-separated integers $u_{i}$ and $v_{i}$ $1 \le u_{i}, v_{i} \le N, u_{i} \ne v_{i}$ describing the pair of farms connected by the trail.

Output

  • Line 1: A single line containing the number of assignments of trails to farms, taken modulo 1,000,000,007. If no assignment satisfies the above conditions output 0.

Examples

Input 1

5 4
1 2
3 2
4 5
4 5

Output 1

6

Note that there can be two trails between the same pair of farms.

There are 6 possible assignments. Letting $\{a,b,c,d\}$ mean that farm 1 builds trail a, farm 2 builds trail b, farm 3 builds trail c, and farm 4 builds trail d, the assignments are: {2, 3, 4, 5} {2, 3, 5, 4} {1, 3, 4, 5} {1, 3, 5, 4} {1, 2, 4, 5} {1, 2, 5, 4}

Problem credits: Mark Gordon, 2011

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.