#K68747. Maximum Uniqueness Value

    ID: 32933 Type: Default 1000ms 256MiB

Maximum Uniqueness Value

Maximum Uniqueness Value

You are given a tree representing a multiverse, where each edge has a weight representing the degree of uniqueness between two universes. By choosing any node as the root, the uniqueness value of the universe is defined as the sum of weights on all edges directed away from the root. In other words, if the tree has \(n\) nodes and edge weights \(w_i\), then when the tree is rooted appropriately the uniqueness value is given by \(\sum_{i=1}^{n-1} w_i\).

Note: The input forms an undirected tree with \(n\) nodes and \(n-1\) edges. For any valid tree, the maximum uniqueness value is simply the sum of all edge weights.

inputFormat

The first line contains an integer (n) representing the number of nodes. Each of the next (n-1) lines contains three integers (u), (v), and (w), indicating that there is an edge between node (u) and node (v) with weight (w).

outputFormat

Output a single integer representing the maximum uniqueness value of the tree.## sample

4
0 1 3
1 2 2
1 3 4
9