You are given a tree with nodes, where each edge has a positive cost. Let and be any two adjacent nodes. Define as the maximum cost of all paths (with no repeated nodes) whose first step goes from to . Define as the sum of for all adjacent to . Please compute the maximum value of among all nodes .
Input consists of several cases. Every case begins with the number of nodes , followed by edges, each one with two different nodes and the cost of the edge between them. Assume . The nodes are numbered starting at zero. Each cost is an integer number between 1 and 1000. The given graph is always a tree. The number of steps between any two nodes is never larger than 1000.
For every case, print the maximum , and how many nodes achieve such a value.
Author: Salvador Roura
Generation: 2026-01-25T10:29:40.242Z
© Jutge.org, 2006–2026.
https://jutge.org