CF855C.Helga Hufflepuff's Cup

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Harry, Ron and Hermione have figured out that Helga Hufflepuff's cup is a horcrux. Through her encounter with Bellatrix Lestrange, Hermione came to know that the cup is present in Bellatrix's family vault in Gringott's Wizarding Bank.

The Wizarding bank is in the form of a tree with total n vaults where each vault has some type, denoted by a number between 1 to m. A tree is an undirected connected graph with no cycles.

The vaults with the highest security are of type k, and all vaults of type k have the highest security.

There can be at most x vaults of highest security.

Also, if a vault is of the highest security, its adjacent vaults are guaranteed to not be of the highest security and their type is guaranteed to be less than k.

Harry wants to consider every possibility so that he can easily find the best path to reach Bellatrix's vault. So, you have to tell him, given the tree structure of Gringotts, the number of possible ways of giving each vault a type such that the above conditions hold.

哈利、罗恩和赫敏已经发现赫尔加·赫奇帕奇的金杯是一个魂器。通过与贝拉特里克斯·莱斯特兰奇的交锋,赫敏得知这只金杯存放在贝拉特里克斯家族在古灵阁巫师银行的金库中。

古灵阁巫师银行的结构是一棵包含总共 nn 个金库的树;每个金库具有某种类型,用 11 到 mm 之间的整数表示。树是一种无向连通无环图。

安全级别最高的金库类型为 kk,且所有类型为 kk 的金库均具有最高安全级别。

最高安全级别的金库数量至多为 xx 个。

此外,若某个金库属于最高安全级别,则其所有相邻金库一定不是最高安全级别,且其类型一定小于 kk。

为了充分考虑所有可能性,从而便于哈利快速找到通往贝拉特里克斯金库的最佳路径,你需要告诉他:在给定古灵阁金库树形结构的前提下,满足上述所有条件的、为每个金库分配类型的方案总数是多少?

输入格式

The first line of input contains two space separated integers, n and m — the number of vaults and the number of different vault types possible. (1 ≤ n ≤ 105, 1 ≤ m ≤ 109).

Each of the next n - 1 lines contain two space separated integers u__i and v__i (1 ≤ u__i, v__i ≤ n) representing the i-th edge, which shows there is a path between the two vaults u__i and v__i. It is guaranteed that the given graph is a tree.

The last line of input contains two integers k and x (1 ≤ k ≤ m, 1 ≤ x ≤ 10), the type of the highest security vault and the maximum possible number of vaults of highest security.

输入的第一行包含两个以空格分隔的整数 nn 和 mm —— 分别表示保险库的数量以及可能的不同保险库类型的数量。(1 ≤ n ≤ 1051 \le n \le 10^5,1 ≤ m ≤ 1091 \le m \le 10^9)

接下来的 n − 1n - 1 行中,每行包含两个以空格分隔的整数 uiu_i 和 viv_i(1 ≤ ui, vi ≤ n1 \le u_i,\,v_i \le n),表示第 ii 条边,表明保险库 uiu_i 与 viv_i 之间存在一条路径。保证所给图是一棵树。

输入的最后一行包含两个整数 kk 和 xx(1 ≤ k ≤ m1 \le k \le m,1 ≤ x ≤ 101 \le x \le 10),分别表示最高安全等级保险库的类型以及最高安全等级保险库的最大可能数量。

输出格式

Output a single integer, the number of ways of giving each vault a type following the conditions modulo 109 + 7.

输出一个整数,表示在满足条件的情况下为每个保险库分配类型的方案数,结果对 109+710^9 + 7 取模。

输入输出样例

  • 输入#1

    4 2
    1 2
    2 3
    1 4
    1 2

    输出#1

    1
  • 输入#2

    3 3
    1 2
    1 3
    2 1

    输出#2

    13
  • 输入#3

    3 1
    1 2
    1 3
    1 1

    输出#3

    0

说明/提示

In test case 1, we cannot have any vault of the highest security as its type is 1 implying that its adjacent vaults would have to have a vault type less than 1, which is not allowed. Thus, there is only one possible combination, in which all the vaults have type 2.

在测试用例 1 中,我们不能有任何最高安全级别的保险库,因为其类型为 1,这意味着其相邻保险库的类型必须小于 1,而这是不允许的。因此,仅存在一种可能的组合,即所有保险库的类型均为 2。

输入解题思路,AI测评打分。不知道怎么写?

首页