{"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":"HTML","content":"树的定义不再给出。\u003cbr\u003e\n\n给定n个点的树。\n对于一个长度为n的排列p,它的权值为:\n \u003cimg alt\u003d\"btriangle.png\" src\u003d\"http://chuantu.xyz/t6/741/1601119456x992248284.png\"\u003e \n\u003cbr\u003e\n其中dist(x,y)表示树上点x到点y的距离。\u003cbr\u003e\n现在你要计算长度为n的所有不同排列在这棵树上的权值和。\u003cbr\u003e\n答案对1e9+7取模"}},{"title":"Input","value":{"format":"HTML","content":"\n多组数据\u003cbr\u003e\n每组数据第一行给定n,\u003cbr\u003e\n之后n-1行给出(a,b,c)表示a到b有一条长度为c的边。\u003cbr\u003e\n保证给定的图是一棵树。\u003cbr\u003e\n\n数据范围:n\u003c\u003d1e5,边\u003c\u003d1e9"}},{"title":"Output","value":{"format":"HTML","content":"输出答案,答案对1e9+7取模"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e3\n1 2 1\n2 3 1\n3\n1 2 1\n1 3 2\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003e16\n24\u003c/pre\u003e"}}]}