#P1120D. Power Tree
Power Tree
No submission language available for this problem.
Description
You are given a rooted tree with vertices, the root of the tree is the vertex . Each vertex has some non-negative price. A leaf of the tree is a non-root vertex that has degree .
Arkady and Vasily play a strange game on the tree. The game consists of three stages. On the first stage Arkady buys some non-empty set of vertices of the tree. On the second stage Vasily puts some integers into all leaves of the tree. On the third stage Arkady can perform several (possibly none) operations of the following kind: choose some vertex he bought on the first stage and some integer , and then add to all integers in the leaves in the subtree of . The integer can be positive, negative of zero.
A leaf is in the subtree of a vertex if and only if the simple path between and the root goes through .
Arkady's task is to make all integers in the leaves equal to zero. What is the minimum total cost he has to pay on the first stage to guarantee his own win independently of the integers Vasily puts on the second stage? Also, we ask you to find all such vertices that there is an optimal (i.e. with cost ) set of vertices containing this one such that Arkady can guarantee his own win buying this set on the first stage.
The first line contains a single integer () — the number of vertices in the tree.
The second line contains integers (), where is the price of the -th vertex.
Each of the next lines contains two integers and (), denoting an edge of the tree.
In the first line print two integers: the minimum possible cost Arkady has to pay to guarantee his own win, and the number of vertices that belong to at least one optimal set.
In the second line print distinct integers in increasing order the indices of the vertices that belong to at least one optimal set.
Input
The first line contains a single integer () — the number of vertices in the tree.
The second line contains integers (), where is the price of the -th vertex.
Each of the next lines contains two integers and (), denoting an edge of the tree.
Output
In the first line print two integers: the minimum possible cost Arkady has to pay to guarantee his own win, and the number of vertices that belong to at least one optimal set.
In the second line print distinct integers in increasing order the indices of the vertices that belong to at least one optimal set.
Samples
Note
In the second example all sets of two vertices are optimal. So, each vertex is in at least one optimal set.