{"trustable":false,"prependHtml":"\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 async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"MD","content":"给定一棵树,我们定义 $dist(u,v)$ 表示节点 $u$ 到 $v$ 的距离,定义函数 $E(u) \u003d \\sum_{1\u003c\u003dv\u003c\u003dn}{dist(u,v)^k}$。\n\n要求输出 $E(1), E(2), ..., E(n)$ 的值。\n\n---\n\n\u003cdiv class\u003d\"panel_content\"\u003e\n There is a tree,there is a life.Can you solve this problem about tree?\u003cbr\u003e\n Here we have a tree which has n vertices.\u003cbr\u003e\n We define dist(u, v) as the number of edges on the path from u to v.\u003cbr\u003e\n And for each vertices u , define E\u003csub\u003eu\u003c/sub\u003e \u003d\u003cimg style\u003d\"max-width:100%;\" src\u003d\"CDN_BASE_URL/cadb02c2b1cb2847dec9865c0f9ed175?v\u003d1681737818\"\u003e\u003cbr\u003e\n Give you the tree and k.\u003cbr\u003e\n Print E\u003csub\u003ei\u003c/sub\u003e for every vertices(from 1 to n).(mod 10007 for convenience).\n\u003c/div\u003e"}},{"title":"Input","value":{"format":"MD","content":"The first line contains integer T(1 \u0026#x14; T \u0026#x14; 5),denote the number of the test cases.\u003cbr\u003e\n For each test cases,the first line contains two integers n,k(1\u0026lt;\u003dn\u0026lt;\u003d50000, 1\u0026lt;\u003dk\u0026lt;\u003d500).\u003cbr\u003e\n Then next n-1 lines,each lines contains two integer a,b(1\u0026lt;\u003da, b\u0026#x14;\u0026lt;\u003dn),denote there is an edge between a, b."}},{"title":"Output","value":{"format":"MD","content":"For each test cases,print n lines,the i-th line contains E\u003csub\u003ei\u003c/sub\u003e."}},{"title":"Sample","value":{"format":"MD","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\u003e\u003cpre\u003e1\n5 3\n1 2\n2 3\n3 4\n4 5\u003c/pre\u003e\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e\u003cpre\u003e100\n37\n18\n37\n100\u003c/pre\u003e\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hint","value":{"format":"MD","content":"\u003cbr\u003e\nThank oimaster for this problem :).\u003cbr\u003e"}}]}