{"trustable":true,"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\u003eRanching and the cowboy tradition originated in Spain, out of the necessity to handle large herds of grazing animals on dry land from horseback. During the Reconquista, members of the Spanish nobility and various military orders received large land grants that the Kingdom of Castile had conquered from the Moors. These landowners were to defend the lands put into their control and could use them for earning revenue. In the process, it was found that open-range breeding of sheep and cattle (under the Mesta system) was the most suitable use for vast tracts, particularly in the parts of Spain now known as Castilla-La Mancha, Extremadura and Andalusia.\u003c/p\u003e\u003ccenter\u003e \u003cimg class\u003d\"tex-graphics\" src\u003d\"CDN_BASE_URL/df63d86fb4dce9c408b473dc78c3c7b0?v\u003d1714454641\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \u003cspan class\u003d\"tex-font-style-sl\"\u003eThe historic 101 Ranch in Oklahoma, US. Public domain.\u003c/span\u003e \u003c/center\u003e\u003cp\u003eJace is an employee at the International Cattle Production Company (ICPC), whose mission today is to help his client Karn to build a new cattle ranch. Both Jace and Karn agree that the ranch should be surrounded by fences to ensure security, and the shape of the ranch should be a simple polygon. Recall that a simple polygon is a polygon that does not intersect itself and has no holes. That is, it is a flat shape consisting of straight, non-intersecting line segments that are joined to form a single closed path. A simple polygon always has a measurable and strictly positive area.\u003c/p\u003e\u003cp\u003eThere are $$$n$$$ shops selling fence segments in the town where Karn lives, they are numbered from $$$1$$$ to $$$n$$$ for convenience. Exactly $$$n-1$$$ bidirectional roads are connecting the shops, and there is exactly one simple path to travel between any two shops using those roads. In other words, the shops and roads form a tree in graph theory. The $$$i$$$-th shop only has a single fence segment for sale, whose length is $$$a_i$$$. Jace plans to travel from one shop $$$x$$$ to another shop $$$y$$$, and buy all fence segments from the shops on the only simple path from $$$x$$$ to $$$y$$$ (including $$$x$$$ and $$$y$$$). Then, he will try to build the fence (as mentioned above, it must be a simple polygon) with the segments he has bought. Since Karn doesn\u0027t want to waste any money, Jace must use all the segments in the fence. Please help Jace calculate how many pairs $$$(x,y)$$$ are there such that $$$x\u0026lt;y$$$, and Jace can build a valid fence if he travels from $$$x$$$ to $$$y$$$.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe input contains multiple cases. The first line of the input contains a single positive integer $$$T$$$, the number of cases.\u003c/p\u003e\u003cp\u003eFor each case, the first line of the input contains a single integer $$$n \\ (1 \\le n \\le 2\\cdot 10^5)$$$, the number of shops. The second line contains $$$n$$$ integers, where the $$$i$$$-th ($$$1 \\le i \\le n$$$) integer $$$a_i\\ (1 \\le a_i \\le 10^9)$$$ denotes the length of the fence segment on sale at the $$$i$$$-th shop. The following $$$n-1$$$ lines each contains two integers $$$u,v \\ (1\\le u,v \\le n)$$$, denoting a bidirectional road between shop $$$u$$$ and shop $$$v$$$. It is guaranteed that the shops and roads form a tree.\u003c/p\u003e\u003cp\u003eIt is guaranteed that the sum of $$$n$$$ over all cases doesn\u0027t exceed $$$4\\cdot 10^5$$$.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eFor each case, print a single integer in a single line, the number of valid pairs $$$(x,y)$$$.\u003c/p\u003e"}},{"title":"Examples","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\u003e2\n3\n1 10 100\n1 2\n3 2\n5\n1 1 1 1 1\n1 2\n1 3\n1 4\n1 5\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e0\n6\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eIn the second sample case, the following pairs are valid: $$$(2,3),\\ (2,4),\\ (2,5),\\ (3,4),\\ (3,5),\\ (4,5)$$$.\u003c/p\u003e"}}]}