8448: Bovine Alliance

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

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 <= N <= 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 <= 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.

贝茜和她附近农场的奶牛朋友们最终决定,她们要修一些道路将她们的农场连接起来,努力组成一个联盟来对付农民。

 

共有 N 个农场,最开始计划每个农场修建一条通往另一个农场的道路,也就是说一共修建 N 条道路。

 

然而,在项目实施了几个月后,只有 M 条道路被真正修建完成。

 

现在,农场之间发生了激烈的争吵,主要的争议点在于这 M 条道路究竟是哪些农场修建完成的。

 

争论影响着联盟的和睦,为了缓和紧张的局势,贝茜希望计算出共有多少种修建出这 M 条道路的不同可能性。

 

例如,如果存在一条连接农场 3 和农场 4 的道路,一种可能性是该道路由农场 3 的牛修建完成,另一种可能性是该道路由农场 4 的牛修建完成。

 

如果两个关于修建道路归属的合理推测中至少存在一条道路被认为是由不同农场修建完成的,那么这两个推测被认为是不同的。

 

请输出所有关于修建道路归属的合理推测的总数量对 109+7 取模后的结果。

输入格式

1 行:两个整数 N M

 

2..M+1 行:第 i+1 行描述第 i 条道路,每行包含两个整数 ui vi,表示农场 ui 和农场 vi 之间存在一条道路。

 

输出格式

输出所有关于修建道路归属的合理推测的总数量对 109+7 取模后的结果。

 

如果不存在满足条件的合理推测,则输出 0

 

输入样例 复制

5 4
1 2
3 2
4 5
4 5

输出样例 复制

6

数据范围与提示

1N105,

1M<N,

1ui,viN,

uivi



共有 6 种关于修建道路归属的合理推测。

 

{a,b,c,d} 表示农场 a 修建了道路 1,农场 b 修建了道路 2,农场 c 修建了道路 3,农场 d 修建了道路 4

 

所有合理推测如下:

 

{2, 3, 4, 5}

{2, 3, 5, 4}

{1, 3, 4, 5}

{1, 3, 5, 4}

{1, 2, 4, 5}

{1, 2, 5, 4}