# 【Codeforces 736C】Ostap and Tree

### Code

#include<bits/stdc++.h>
#define LL long long
#define relax(a, b, c) (a = (a + (LL)b * c) % MOD)
using namespace std;

const int N = 300;
const int MOD = 1000000007;
const int BAS = 120;

int n, K, head[N], nxt[N], to[N];
int *f[N], arr_back[N][N];

inline int read() {
char c = getchar();
int ret = 0, f = 1;
while (c < '0' || c > '9') {
f = c == '-'? -1: 1;
c = getchar();
}
while ('0' <= c && c <= '9') {
ret = ret * 10 + c - '0';
c = getchar();
}
return ret * f;
}

inline void AddEdge(int u, int v) {
static int E = 1;
to[++E] = v; nxt[E] = head[u]; head[u] = E;
to[++E] = u; nxt[E] = head[v]; head[v] = E;
}

inline void DFS(int w, int fa) {
static int arr1_back[N], *tmp = arr1_back + BAS;
f[w][-1] = f[w][K] = 1;
for (int i = head[w], t; i; i = nxt[i]) {
if ((t = to[i]) != fa) {
DFS(t, w);
for (int j = -K; j <= K; j++) {
tmp[j] = f[w][j];
f[w][j] = 0;
}
for (int j = -K; j <= K; j++) {
for (int k = -K - 1; k < K; k++) {
if (j >= 0 && k >= 0) {
relax(f[w][max(j, k)], tmp[j], f[t][k + 1]);
} else if ((j < 0 && k >= 0) || (j >= 0 && k < 0)) {
int ge = max(j, k), le = min(j, k);
if (ge + 1 >= -le) {
relax(f[w][ge], tmp[j], f[t][k + 1]);
} else {
relax(f[w][le], tmp[j], f[t][k + 1]);
}
} else {
relax(f[w][min(j, k)], tmp[j], f[t][k + 1]);
}
}
}
}
}
}

int main() {
n = read(); K = read();
for (int i = 1; i < n; i++) {
AddEdge(read(), read());
}
for (int i = 1; i <= n; i++) {
f[i] = arr_back[i] + BAS;
}
DFS(1, 1);
int ans = 0;
for (int i = 0; i <= K; i++) {
ans = (ans + f[1][i]) % MOD;
}
printf("%d\n", ans);
return 0;
}


## 271 thoughts to “【Codeforces 736C】Ostap and Tree”

1. I think this is a real great blog post. Awesome.

2. Muchos Gracias for your blog.Much thanks again. Cool.

3. A big thank you for your article.Really looking forward to read more. Really Cool.

4. Thanks for sharing, this is a fantastic article post.Thanks Again. Really Great.

5. Thanks for sharing, this is a fantastic blog post.Much thanks again. Want more.

6. wow, awesome post.Really looking forward to read more. Really Great.

7. Muchos Gracias for your article post.Really thank you! Awesome.

8. Very informative article. Fantastic.

9. I am so grateful for your article post. Much obliged.

10. Great post about this. I’m surprised to see someone so educated in the matter. I am sure my visitors will find that very useful.

11. Really enjoyed this article post. Really Great.

12. Great, thanks for sharing this blog post.Much thanks again. Much obliged.

13. Really informative blog article.Really thank you! Much obliged.

14. Really informative article post.Much thanks again. Want more.

15. Thanks so much for the blog article.Much thanks again. Keep writing.

16. Thanks-a-mundo for the blog. Want more.

17. Very good post.Really looking forward to read more. Want more.

18. Very good blog article.Much thanks again. Much obliged.

19. This is one awesome article post.Really looking forward to read more. Much obliged.

20. Very good blog post.Really thank you!

21. Fantastic blog.Much thanks again. Want more.

22. Thank you ever so for you blog post. Really Cool.

23. wow, awesome article.Much thanks again. Really Cool.

24. Wow, great blog post.Much thanks again. Fantastic.

25. Appreciate you sharing, great article. Really Cool.

26. Say, you got a nice blog post.Really looking forward to read more. Really Great.

27. Very neat article.Really thank you! Will read on…

28. I really liked your article post.Really thank you! Keep writing.

29. I think this is a real great post.Really looking forward to read more. Really Great.

30. Say, you got a nice post.Thanks Again. Keep writing.

31. Hi there! I know this is kinda off topic but I was wondering if you knew where I could
locate a captcha plugin for my comment form?

I’m using the same blog platform as yours and I’m having problems finding one?

Thanks a lot!

32. Really appreciate you sharing this article post.Really thank you! Want more.

33. I appreciate you sharing this blog article.Really looking forward to read more. Really Great.

34. Hello there, You have done a fantastic job. I will definitely digg
it and personally suggest to my friends. I am confident they will be benefited from this
site.

35. Enjoyed every bit of your blog article. Will read on…

36. I know this if off topic but I’m looking into starting my own blog and
was wondering what all is needed to get set up?
I’m assuming having a blog like yours would cost a pretty
penny? I’m not very web smart so I’m not 100% sure. Any recommendations or advice
would be greatly appreciated. Thank you

37. Looking forward to reading more. Great blog post.Thanks Again. Great.

38. wow, awesome blog post.Really thank you! Really Great.

39. Wow, great post.Really looking forward to read more. Awesome.

40. Really enjoyed this article post.Much thanks again. Want more.

41. Really appreciate you sharing this blog article.Really thank you! Great.

42. I loved your article.Really thank you! Want more.

43. I really liked your blog post. Thanks Again. Really Cool.

44. wow, awesome blog article.Thanks Again. Great.

45. I appreciate you sharing this blog article.Much thanks again. Really Great.

46. A big thank you for your post.Really looking forward to read more. Awesome.

47. Looking forward to reading more. Great blog. Really Great.

48. Hey, thanks for the blog post.Much thanks again.

49. It’s an remarkable piece of writing for all the internet users; they will obtain benefit from it I am sure.

50. Very neat article.Thanks Again. Will read on…

51. Great post.Really looking forward to read more. Cool.

52. Incredible! This blog looks exactly like my old one!
It’s on a entirely different topic but it has pretty much the same layout and design. Great choice of
colors!

53. Thanks again for the blog post.Much thanks again. Want more.

54. Thanks for sharing, this is a fantastic article post.Much thanks again.

55. Please let me know if you’re looking for a article writer for
your blog. You have some really good articles and I think
I would be a good asset. If you ever want to take some of the load off, I’d
love to write some content for your blog in exchange for a link back to
mine. Please shoot me an email if interested. Many thanks!

56. Great, thanks for sharing this post.Much thanks again. Really Cool.

57. Really informative blog.Really looking forward to read more. Fantastic.

58. Really appreciate you sharing this article post.Really thank you! Want more.

59. I’m curious to find out what blog platform you’re using?
I’m having some small security issues with my latest website and I would like to find something more risk-free.
Do you have any recommendations?

60. Hey, thanks for the post.Really thank you! Great.

61. Really enjoyed this blog article.Much thanks again. Cool.

62. Appreciate you sharing, great article.Really thank you!

63. Thanks a lot for the article post.Much thanks again. Much obliged.

64. A round of applause for your article post. Cool.

65. Wow, great blog.Really thank you! Awesome.

66. Thanks for sharing, this is a fantastic blog.Really thank you! Will read on…

67. Stunning quest there. What happened after?

Thanks!

68. Thank you for your blog article.Really thank you! Want more.

69. Thanks for the article.Really looking forward to read more. Keep writing.

70. Hey, thanks for the article.Really thank you! Really Great.

71. Right now it appears like WordPress is the top blogging platform out there right now.
(from what I’ve read) Is that what you’re using
on your blog?

72. Very good blog. Want more.

73. Great weblog right here! Additionally your
site so much up very fast! What host are you using?
Can I am getting your affiliate link to your host?
I wish my site loaded up as fast as yours lol

74. I am so grateful for your post.Much thanks again. Great.

75. Muchos Gracias for your post. Keep writing.

76. Hi! This is my first comment here so I just wanted to
give a quick shout out and say I genuinely enjoy reading your posts.
Can you suggest any other blogs/websites/forums
that cover the same topics? Thanks a lot!

77. I am so grateful for your blog article.Thanks Again. Cool.

78. Hey, thanks for the blog post.Much thanks again. Will read on…

79. Hmm it seems like your site ate my first comment (it was extremely long) so I
guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog.
I too am an aspiring blog writer but I’m still new to everything.
Do you have any helpful hints for rookie blog writers? I’d
really appreciate it.

80. Im thankful for the blog article. Awesome.

81. I’m not that much of a online reader to be honest but your sites really nice, keep it up!
I’ll go ahead and bookmark your site to come back in the future.
All the best

82. Thanks a lot for the post.Really thank you!

83. Thanks for the blog.Really looking forward to read more. Want more.

84. Very informative blog.Thanks Again. Will read on…

85. Thanks again for the article. Cool.

86. I cannot thank you enough for the blog.Really looking forward to read more. Really Cool.

87. I really liked your blog article.Thanks Again. Awesome.

88. I think this is a real great article. Really Cool.

89. It is appropriate time to make a few plans for the longer term and it is time to be happy. I have learn this publish and if I could I desire to recommend you some interesting issues or suggestions. Perhaps you can write subsequent articles relating to this article. I desire to learn even more issues about it!

90. Thanks again for the blog post.Thanks Again. Want more.

91. I appreciate you sharing this article post. Great.

92. I truly appreciate this article post.Really thank you! Really Cool.

93. Thank you for your blog.Really looking forward to read more. Keep writing.

94. Thank you for the auspicious writeup. It in fact was a amusement account it.

Look advanced to far added agreeable from you! However,
how could we communicate?

95. Thanks again for the blog.Much thanks again. Cool.

96. A big thank you for your blog post.Thanks Again. Great.

97. I am so grateful for your article post.Really looking forward to read more. Awesome.

98. I truly appreciate this blog.Really thank you! Will read on…

99. I really enjoy the blog article.Really thank you! Keep writing.

100. Major thankies for the blog.

101. Muchos Gracias for your article.Much thanks again. Really Cool.

102. Muchos Gracias for your article post. Fantastic.

103. Really enjoyed this article.Much thanks again. Keep writing.

104. Really appreciate you sharing this post.Thanks Again. Really Cool.

105. Thanks again for the article.Thanks Again. Much obliged.

106. Major thanks for the article.Thanks Again.

107. Thanks again for the article.Thanks Again. Want more.

108. Really informative post.Really thank you! Much obliged.

109. A big thank you for your blog article.Really thank you! Fantastic.

110. Very informative blog post.Much thanks again. Really Cool.

111. A round of applause for your post.Really thank you! Cool.

112. Thanks again for the post.Thanks Again. Awesome.

113. Great article post.Thanks Again. Want more.

114. Thank you ever so for you blog article.Much thanks again. Keep writing.

115. Looking forward to reading more. Great article post.Thanks Again. Fantastic.

116. Thanks for the blog article.Much thanks again. Keep writing.

117. It’s hard to find experienced people for this subject, but you sound like you know what you’re talking about!
Thanks

118. Really appreciate you sharing this blog post.Much thanks again. Want more.

119. Thank you ever so for you article.Really looking forward to read more. Cool.

120. Really enjoyed this article.Much thanks again. Much obliged.

121. When some one searches for his necessary
thing, thus he/she wants to be available that in detail,
thus that thing is maintained over here.

122. Looking forward to reading more. Great blog article. Much obliged.

123. Im grateful for the blog post.Thanks Again. Cool.

124. Great, thanks for sharing this blog post.

125. I think this is a real great article post.Really thank you! Will read on…

126. I am not sure where you’re getting your information, but good
topic. I needs to spend some time learning much
more or understanding more. Thanks for fantastic info I was looking for this info for my mission.

127. Hey, thanks for the blog post.Really looking forward to read more. Much obliged.

128. Thank you ever so for you blog.Really looking forward to read more. Cool.

129. Great, thanks for sharing this post. Cool.

130. Thanks a lot for the article.Thanks Again. Really Cool.

131. Thanks-a-mundo for the article post. Much obliged.

132. Really informative blog article.Thanks Again. Really Cool.

133. Really informative blog. Keep writing.

134. I appreciate you sharing this blog article.

135. Hey, thanks for the article.Really thank you! Cool.

136. Hey, thanks for the article. Fantastic.

137. I really like and appreciate your blog article.Thanks Again. Awesome.

138. Very good blog article. Great.

139. I am so grateful for your article.Much thanks again. Really Cool.

140. Please let me know if you’re looking for a article author for your blog.
You have some really great posts and I believe I would be a good asset.
If you ever want to take some of the load off, I’d absolutely love to write some articles for your blog
in exchange for a link back to mine. Please shoot me an email if interested.

Kudos!

141. Really informative article.

142. Hey, thanks for the post.Really thank you! Keep writing.

143. It’s awesome for me to have a website, which is beneficial for my know-how.
thanks admin

144. I am so grateful for your blog article.Thanks Again. Awesome.

145. I value the blog post.Really looking forward to read more. Awesome.

146. Thank you ever so for you post.Really looking forward to read more. Much obliged.

147. Appreciate you sharing, great article post. Really Great.

148. I think this is a real great blog article.Really looking forward to read more. Awesome.

149. Really enjoyed this post.Thanks Again. Really Cool.

150. I value the blog.Really looking forward to read more. Keep writing.

151. Someone necessarily assist to make seriously posts I would state.
That is the very first time I frequented your website page and
thus far? I amazed with the research you made to create this particular put up
incredible. Excellent process!

152. Really informative article.Thanks Again. Will read on…

153. I appreciate you sharing this blog article.Really looking forward to read more. Will read on…

154. Thanks a lot for the blog post.Really thank you! Really Cool.

155. Say, you got a nice blog article. Want more.

156. A big thank you for your blog article.Really looking forward to read more. Great.

157. Thank you for your article.Thanks Again. Want more.

158. Very good article post.Much thanks again. Great.

159. A big thank you for your article post.Thanks Again. Really Cool.

160. Thanks so much for the blog article.Much thanks again. Really Cool.

161. Very informative article.Much thanks again. Will read on…

162. Great, thanks for sharing this blog post.Really thank you! Great.

163. Thanks again for the blog post.Really looking forward to read more. Really Great.

164. Looking forward to reading more. Great blog post.Thanks Again. Will read on…

165. Great blog post. Cool.

166. I cannot thank you enough for the blog article.Much thanks again. Awesome.

167. Major thanks for the article post. Cool.

168. Hi it’s me, I am also visiting this web site daily, this web page is really
nice and the users are really sharing nice thoughts.

169. I am so grateful for your blog article.Much thanks again.

170. It’s not my first time to visit this web page, i am visiting this
website dailly and take fastidious data from here
daily.

171. Major thanks for the post.Really looking forward to read more. Fantastic.

172. Thanks a lot for the post.Really looking forward to read more. Great.

173. I am so grateful for your article.Really looking forward to read more. Great.

174. Wow, great blog.Much thanks again. Really Great.

175. Im grateful for the post.Thanks Again. Will read on…

176. I really enjoy the blog post. Great.

177. Thanks for sharing, this is a fantastic article post.Thanks Again. Much obliged.

178. Looking forward to reading more. Great blog.Thanks Again. Keep writing.

179. Awesome blog article. Really Cool.

180. Im grateful for the blog article.Really looking forward to read more.

181. Hey, thanks for the blog.Thanks Again. Really Great.

182. A big thank you for your blog post.Really looking forward to read more.

183. This is one awesome article post. Keep writing.

184. Looking forward to reading more. Great article.Much thanks again. Much obliged.

185. I really like and appreciate your post.Really thank you! Cool.

186. First of all I would like to say wonderful blog! I had a quick question in which I’d like to ask if you don’t mind.
I was curious to find out how you center yourself and clear your thoughts
prior to writing. I’ve had a difficult time clearing my thoughts in getting my ideas out
there. I truly do enjoy writing however it just seems like
the first 10 to 15 minutes are usually wasted just trying to figure out how to begin. Any recommendations or
tips? Appreciate it!

187. Im obliged for the blog.Thanks Again. Great.

188. Thanks for the blog post.Much thanks again. Want more.

189. Great article.Much thanks again.

190. Major thankies for the blog post.Really looking forward to read more.

191. Im obliged for the blog article.Much thanks again. Keep writing.

192. Thank you for your article.Much thanks again.

193. It is perfect time to make some plans for the future
and it is time to be happy. I have read this post
and if I could I want to suggest you some interesting things
or advice. Maybe you can write next articles referring to this article.
I wish to read more things about it!

194. Muchos Gracias for your post. Great.

195. Thanks for sharing, this is a fantastic blog post.Really thank you! Keep writing.

196. Really appreciate you sharing this blog post.Really thank you! Cool.

197. Great, thanks for sharing this blog post.Thanks Again. Want more.

198. Thanks for the blog.Really looking forward to read more. Awesome.

199. Really informative blog article.Really looking forward to read more. Keep writing.

200. I think this is a real great blog post.Thanks Again. Awesome.

201. Fantastic blog article.Really looking forward to read more. Fantastic.

202. Im obliged for the blog post.Thanks Again.

203. I am so grateful for your post.Really thank you! Fantastic.

204. I really like and appreciate your blog article.Really looking forward to read more. Much obliged.

205. Im obliged for the blog post.Really looking forward to read more. Awesome.

206. Thank you ever so for you blog article.Really looking forward to read more. Really Cool.

207. Awesome blog.Thanks Again. Awesome.

208. Really appreciate you sharing this blog article.Thanks Again.

209. Looking forward to reading more. Great article.Really thank you! Want more.

210. I cannot thank you enough for the article post.Really looking forward to read more. Really Cool.

211. I am so grateful for your post.Really looking forward to read more. Want more.

212. Awesome blog. Will read on…

213. Keep on writing, great job!|

214. WOW just what I was looking for. Came here by searching for keyword|

215. I really like and appreciate your post.Really thank you! Fantastic.

216. Really enjoyed this article. Awesome.

217. It’s amazing designed for me to have a site, which is valuable designed for my experience. thanks admin|

218. Enjoyed every bit of your blog post.Really looking forward to read more. Much obliged.

219. I really like and appreciate your post.Thanks Again. Fantastic.

220. Thanks-a-mundo for the blog post.Thanks Again. Really Great.

221. Really informative article post.Thanks Again. Great.

222. Wonderful article! We are linking to this great post on our website. Keep up the good writing.|

223. Muchos Gracias for your article post.Really looking forward to read more. Really Cool.

224. Im thankful for the post.Really looking forward to read more. Keep writing.

225. Pretty part of content. I just stumbled upon your weblog and in accession capital to claim that I acquire in fact loved account your blog posts. Any way I’ll be subscribing to your feeds or even I success you access consistently fast.|

226. Thanks again for the blog article.Really thank you! Really Cool.

227. Hey, thanks for the blog.Really looking forward to read more. Great.

228. Really appreciate you sharing this blog.Really thank you! Will read on…

229. Thank you ever so for you article.Much thanks again. Cool.

230. I love what you guys are usually up too. Such clever work and exposure! Keep up the excellent works guys I’ve added you guys to blogroll.|

231. I am actually pleased to read this website posts which carries lots of valuable information, thanks for providing these statistics.|

232. wow, awesome blog article.Thanks Again. Great.

233. Im grateful for the blog post.Really looking forward to read more. Awesome.

234. Looking forward to reading more. Great blog article.Really looking forward to read more. Really Cool.

235. Howdy, I believe your website could be having internet browser compatibility issues. When I take a look at your website in Safari, it looks fine however, if opening in Internet Explorer, it’s got some overlapping issues. I simply wanted to give you a quick heads up! Besides that, excellent website!|

236. wow, awesome blog.Really thank you!

237. Whats up very nice site!! Guy .. Excellent .. Wonderful .. I’ll bookmark your blog and take the feeds also? I am glad to seek out numerous useful info here in the post, we want work out extra techniques on this regard, thanks for sharing. . . . . .|

238. Your style is so unique in comparison to other people I have read stuff from. Many thanks for posting when you have the opportunity, Guess I will just bookmark this site.|

239. Fantastic post.Really thank you! Will read on…

240. I am so grateful for your blog post.Much thanks again. Keep writing.

241. Very good blog.Really thank you! Fantastic.

242. Major thankies for the blog post.Really thank you! Fantastic.

243. I loved your article.Really looking forward to read more. Great.

244. I know this if off topic but I’m looking into starting my own blog and was curious what all is required to get setup? I’m assuming having a blog like yours would cost a pretty penny? I’m not very internet savvy so I’m not 100 certain. Any tips or advice would be greatly appreciated. Cheers|

245. Muchos Gracias for your article post.Really looking forward to read more. Really Great.

246. Really appreciate you sharing this article post.Really thank you! Will read on…

247. Thanks-a-mundo for the article.Really looking forward to read more. Awesome.

248. Great, thanks for sharing this blog.Really thank you! Awesome.

249. Say, you got a nice blog.Much thanks again. Much obliged.

250. Hi there, I found your web site by means of Google while searching for a related matter, your web site got here up, it appears great. I’ve bookmarked it in my google bookmarks.

251. It’s actually very difficult in this active life to listen news on TV, so I simply use the web for that purpose, and obtain the newest news.|