{"trustable":false,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003e众所周知,具有 $$$n$$$ 个节点、$$$n-1$$$ 条边的无向连通图被称为一棵\u003cstrong\u003e树\u003c/strong\u003e。给定整数 $$$d$$$,以及由 $$$n$$$ 个节点组成的树。每个节点 $$$i$$$ 都有与之相关联的值 $$$a_i$$$。\u003c/p\u003e\n\n\u003cp\u003e如果满足以下条件,我们称树节点的集合 $$$S$$$ 是\u003cstrong\u003e有效\u003c/strong\u003e的:\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003e$$$S$$$ 非空。\u003c/li\u003e\n\u003cli\u003e$$$S$$$ 是连通的。换句话说,如果节点 $$$u$$$ 和 $$$v$$$ 在集合 $$$S$$$ 中,那么在 $$$u$$$ 和 $$$v$$$ 之间的简单路径中包含的所有节点,也应当位于集合 $$$S$$$ 中。\u003c/li\u003e\n\u003cli\u003e$$$\\displaystyle \\max_{\\substack{u \\in S}} a_u - \\min_{\\substack{v \\in S}} a_v \\leq d$$$\u003c/li\u003e\n\u003c/ol\u003e\n\n\u003cp\u003e你的任务是计算有效集合的数量。由于结果可能非常大,因此必须打印对 $$$10^9+7$$$ 取模的余数。\u003c/p\u003e"}},{"title":"输入","value":{"format":"HTML","content":"\u003cp\u003e第一行包含两个整数 $$$d,n$$$ ($$$0 \\leq d \\leq 2000$$$ 且 $$$1 \\leq n \\leq 2000$$$)。\u003c/p\u003e\n\n\u003cp\u003e第二行包含 $$$n$$$ 个正整数 $$$a_1,a_2,\\dots,a_n$$$ ($$$1 \\leq a_i \\leq 2000$$$) 。\u003c/p\u003e\n\n\u003cp\u003e接下来的 $$$n-1$$$ 行,每行包含一对整数 $$$u,v$$$ ($$$1 \\leq u,v \\leq n$$$),表示在 $$$u$$$ 和 $$$v$$$ 之间存在一条边。保证这些边构成一棵树。\u003c/p\u003e"}},{"title":"输出","value":{"format":"HTML","content":"\u003cp\u003e打印有效集合的数量,结果对 $$$10^9+7$$$ 取模。\u003c/p\u003e"}},{"title":"示例1","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e1 4\n2 1 3 2\n1 2\n1 3\n3 4\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e8\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}},{"title":"示例2","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e0 3\n1 2 3\n1 2\n2 3\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e3\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}},{"title":"示例3","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e4 8\n7 8 7 5 4 6 4 10\n1 6\n1 2\n5 8\n1 3\n3 5\n6 7\n3 4\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e41\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}},{"title":"注意","value":{"format":"HTML","content":"\u003cp\u003e在第一个示例中,恰好有 8 个有效集合:$$$\\{1\\},\\{2\\},\\{3\\},\\{4\\},\\{1,2\\},\\{1,3\\},\\{3,4\\},\\{1,3,4\\}$$$。\u003cbr\u003e集合 $$$\\{1,2,3,4\\}$$$ 不是有效的,因为不满足第三个条件。\u003cbr\u003e集合 $$$\\{1,4\\}$$$ 满足第三个条件,但与第二个条件冲突。\u003c/p\u003e"}}]}