Cost Of Subtree
Time limit1sMemory limit512 MB
Given a tree with weighted edges, find a non-empty connected edge set maximizing its edge count times the minimum edge weight in it.
- Level
Hard8 of 10
- Topics
- Tree, Union-find, Sorting, Greedy
- Solved
- No attempts yet
Problem
A valuable tree with vertices grows near Byteazar's house. Edge has cost assigned to it.
A subtree of the tree is a non-empty connected subset of its edges.
The cost of a subtree is the number of edges in the subtree multiplied by the lowest value of in it.
Byteazar wants to make some money by selling subtrees, so he wants to know the maximum cost of a subtree of his tree.
Input
The first line contains a single integer (), the number of vertices in the tree. Each of the following lines contains three integers , and (; ; ), the vertices connected by the edge and its cost.
Output
Print one integer, the maximum cost of a subtree of the given tree.