Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Given a tree with IN nodes connected by N - 1 edges, rooted at node 1 , each edge in the tree is assigned a
Given a tree with IN nodes connected by N edges, rooted at node each edge in the tree is assigned a value, which can be either positive, negative, or zero. Your task is to calculate, for each node, the smallest total sum of edge values that can be obtained on a simple path from that particular node to any leaf node in the tree
Notes:
A simple path is a path in a tree that does not have repeating vertices.
A node that does not have any child node is called a leaf node
Input format
The first line contains a single integer T which denotes the number of test cases.
For each test case:
The first line contains IN denoting the number of vertices in the tree.
The following IN lines contain spaceseparated integers, u v and w indicating that there is an edge between vertices u & tv and this edge has value w
Output format For each test case, print N integers in a new line, where the the integer depicts the smallest total sum of edge
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started