Allow us to characterize its k-shading as a task of k tones to the edges so that each edge has precisely one tone doled out to it. Note that you don't need to utilize every k tone. A subgraph of shading x comprises of these edges from the first tree, which are doled out shading x, and just those vertices that
Correct answer will be upvoted else Multiple Downvoted. Computer science.
Allow us to characterize its k-shading as a task of k tones to the edges so that each edge has precisely one tone doled out to it. Note that you don't need to utilize every k tone.
A subgraph of shading x comprises of these edges from the first tree, which are doled out shading x, and just those vertices that are adjoining something like one such edge. So there are no vertices of degree 0 in such a subgraph.
The worth of an associated part is the amount of loads of its vertices. Allow us to characterize the worth of a subgraph as a limit of upsides of its associated parts. We will accept that the worth of a void subgraph approaches 0.
There is additionally a worth of a k-shading, which rises to the amount of upsides of subgraphs of every k tone. Given a tree, for every k from 1 to n−1 ascertain the maximal worth of a k-shading.
Input
In the primary line of input, there is a solitary integer t (1≤t≤105) indicating the number of experiments. Then, at that point, t experiments follow.
First line of each experiment contains a solitary integer n (2≤n≤105). The subsequent line comprises of n integers w1,w2,… ,wn (0≤wi≤109), wi rises to the heaviness of I-th vertex. In every one of the accompanying n−1 lines, there are two integers u, v (1≤u,v≤n) portraying an edge between vertices u and v. It is ensured that these edges structure a tree.
The amount of n in all experiments won't surpass 2⋅105.
Output
For each experiment, your
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 4 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)