21563_BovineAlliance

2022-5-16 18:19| 发布者: Hocassian| 查看: 19| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505643552400-Problem List-采集的数据-后羿采集器.html

Pro.ID

21563

Title

Bovine Alliance

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21563

AC

5

Submit

15

Ratio

33.33%

时间&空间限制

  • Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    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.

    输入

    * Line 1: Two space-separated integers N and M

    * Lines 2..1+M: Line i+1 describes the i-th trail.  Each line contains two space-separated integers ui and vi (1 ≤ ui, viN,  uivi) describing the pair of farms connected by the trail.

    输出

    Description

    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.

    Input

    * Line 1: Two space-separated integers N and M

    * Lines 2..1+M: Line i+1 describes the i-th trail.  Each line contains two space-separated integers ui and vi (1 ≤ ui, viN,  uivi) 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.

    Sample Input

    5 4
    1 2
    3 2
    4 5
    4 5

    Sample Output

    6

    Hint

    INPUT DETAILS:

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

    OUTPUT DETAILS:

    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}

    Source

    样例输入

    5 4
    1 2
    3 2
    4 5
    4 5

    样例输出

    6

    提示

    INPUT DETAILS:

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

    OUTPUT DETAILS:

    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}


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部