Discription

Ostap already settled down in Rio de Janiero suburb and started to grow a tree in his garden. Recall that a tree is a connected undirected acyclic graph.

Ostap's tree now has n vertices. He wants to paint some vertices of the tree black such that from any vertex u there is at least one black vertex v at distance no more than k. Distance between two vertices of the tree is the minimum possible number of edges of the path between them.

As this number of ways to paint the tree can be large, Ostap wants you to compute it modulo 109 + 7. Two ways to paint the tree are considered different if there exists a vertex that is painted black in one way and is not painted in the other one.

Input

The first line of the input contains two integers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ min(20, n - 1)) — the number of vertices in Ostap's tree and the maximum allowed distance to the nearest black vertex. Don't miss the unusual constraint for k.

Each of the next n - 1 lines contain two integers ui and vi (1 ≤ ui, vi ≤ n) — indices of vertices, connected by the i-th edge. It's guaranteed that given graph is a tree.

Output

Print one integer — the remainder of division of the number of ways to paint the tree by 1 000 000 007 (109 + 7).

Examples

Input
2 0
1 2
Output
1
Input
2 1
1 2
Output
3
Input
4 1
1 2
2 3
3 4
Output
9
Input
7 2
1 2
2 3
1 4
4 5
1 6
6 7
Output
91

Note

In the first sample, Ostap has to paint both vertices black.

In the second sample, it is enough to paint only one of two vertices, thus the answer is 3: Ostap can paint only vertex 1, only vertex 2, vertices 1 and 2 both.

In the third sample, the valid ways to paint vertices are: {1, 3}, {1, 4}, {2, 3}, {2, 4}, {1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4}, {1, 2, 3, 4}.

状态定义见代码注释,注意合并两个子树的时候如果最近的黑点到根的距离>k那么就相当于没有黑点。

/*
f[x][y][z] => 以x为根的子树中 ,最近的黑点距离x为 y-1 ,
最远的(没有被覆盖到的)白点距离x为 z-1 的方案数。 如果不存在黑点或白点那么那一维是0
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int ha=1000000007;
const int maxn=105;
int hd[maxn],n,m,to[maxn*2],num;
int ne[maxn*2],f[maxn][25][25],k;
int ans=0,g[25][25]; inline int add(int x,int y){
x+=y;
return x>=ha?x-ha:x;
} inline void addline(int x,int y){
to[++num]=y,ne[num]=hd[x],hd[x]=num;
} inline void MERGE(int x,int y){
memset(g,0,sizeof(g)); for(int i=k+1;i>=0;i--)
for(int j=k+1;j>=0;j--) if(f[x][i][j])
for(int I=k+1,NearB,FarW;I>=0;I--)
for(int J=k+1;J>=0;J--) if(f[y][I][J]){
NearB=1<<30;
if(i) NearB=i;
if(I) NearB=min(NearB,I+1);
if(NearB>k+1) NearB=0; FarW=0;
if(j&&(!I||(j+I-1)>k)) FarW=j;
if(J&&(!i||(J+i-1)>k)) FarW=max(FarW,J+1); g[NearB][FarW]=add(g[NearB][FarW],f[x][i][j]*(ll)f[y][I][J]%ha);
} memcpy(f[x],g,sizeof(g));
} void dfs(int x,int fa){
f[x][1][0]=f[x][0][1]=1;
for(int i=hd[x];i;i=ne[i]) if(to[i]!=fa){
dfs(to[i],x);
MERGE(x,to[i]);
}
} inline void calc(){
for(int i=k+1;i>=0;i--) ans=add(ans,f[1][i][0]); /*
for(int i=1;i<=n;i++)
for(int j=0;j<=k+1;j++)
for(int l=0;l<=k+1;l++) printf("f[%d][%d][%d] = %d\n",i,j,l,f[i][j][l]);
*/
} int main(){
scanf("%d%d",&n,&k);
int uu,vv;
for(int i=1;i<n;i++){
scanf("%d%d",&uu,&vv);
addline(uu,vv),addline(vv,uu);
} dfs(1,1);
calc();
printf("%d\n",ans);
return 0;
}

  

Codeforces 735 E Ostap and Tree的更多相关文章

  1. Codeforces Round #382 (Div. 2)E. Ostap and Tree

    E. Ostap and Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  2. codeforces 741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths(启发式合并)

    codeforces 741D Arpa's letter-marked tree and Mehrdad's Dokhtar-kosh paths 题意 给出一棵树,每条边上有一个字符,字符集大小只 ...

  3. codeforces 812E Sagheer and Apple Tree(思维、nim博弈)

    codeforces 812E Sagheer and Apple Tree 题意 一棵带点权有根树,保证所有叶子节点到根的距离同奇偶. 每次可以选择一个点,把它的点权删除x,它的某个儿子的点权增加x ...

  4. codeforces 220 C. Game on Tree

    题目链接 codeforces 220 C. Game on Tree 题解 对于 1节点一定要选的 发现对于每个节点,被覆盖切选中其节点的概率为祖先个数分之一,也就是深度分之一 代码 #includ ...

  5. Codeforces E. Alyona and a tree(二分树上差分)

    题目描述: Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  6. Codeforces 379 F. New Year Tree

    \(>Codeforces \space 379 F. New Year Tree<\) 题目大意 : 有一棵有 \(4\) 个节点个树,有连边 \((1,2) (1,3) (1,4)\) ...

  7. 【27.91%】【codeforces 734E】Anton and Tree

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. codeforces 342E :Xenia and Tree

    Description Xenia the programmer has a tree consisting of n nodes. We will consider the tree nodes i ...

  9. Codeforces Edu3 E. Minimum spanning tree for each edge

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

随机推荐

  1. dubbo 多连接,多线程池.

    1. consumer 多连接 Dubbo protocol options: <dubbo:protocolname=“dubbo” port=“9090” server=“netty” cl ...

  2. React框架搭建单页面应用package.json基本包和依赖包

    { //依赖包 "devDependencies": { //babel "babel-core": "6.24.1", "bab ...

  3. UVa-10474-大理石在哪

    lower_bound()的作用是查找"大于或等于x的第一个位置",但是返回的是地址,所以减去数组的首地址就是偏移量了,也就是整型数字. #include <iostream ...

  4. Python Cookbook3 Python进阶教程 http://python3-cookbook.readthedocs.io/zh_CN/latest/copyright.html

    http://python3-cookbook.readthedocs.io/zh_CN/latest/copyright.html

  5. tabel使用总结

    对日常使用到的tabel做下记录: <table cellspacing="0"><!--单元格间距为零 默认为2 border默认为 0--> <t ...

  6. 【01】let和const命令

    let和const命令   魔芋总结: 01,let声明变量,只在代码块{}内有效. 02,不存在变量提升,只能先声明,再使用.否则报错. 03,暂时性死区 如果代码块中存在let和const声明的变 ...

  7. android 之 TabHost

    TabHost的实现有两种方式,第一种继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost.各个Tab中的内容在布局文件中定义就行了. mainAct ...

  8. Clojure基础

    最近看了一段clojure,下面是从书上摘下来的一下语言基础的精华部分 ;函数的基本形式 (defn average [numbers] (/ (apply + numbers) (count num ...

  9. Webstrom卡顿问题解决

    1.设置node_modules 打开项目,新建node_modules空文件夹,然后右击选择Mark Directory as,选择Excluded. 2.设置ingore文件 files-> ...

  10. 【JavaScript 5—基础知识点】:正则表达式(笔记)

    一.总体概览 1.1,什么是正则 又称正规表示法.常规表示法(英语:Regular Expression,在代码中常简写为regex.regexp或RE),计算机科学的一个概念.正则表达式使用单个字符 ...