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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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 program should print one line containing n−1 integers isolated with a solitary space. The I-th number in a line ought to be the maximal worth of an I-shading of the tree.

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Types of trees
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education