Alex decided to go on a touristic trip over the country.
For simplicity let's assume that the country has 𝑛 cities and 𝑚 bidirectional roads connecting them. Alex lives in city 𝑠 and initially located in it. To compare different cities Alex assigned each city a score 𝑤𝑖 which is as high as interesting city seems to Alex.
You are given a weighted tree consisting of 𝑛 vertices. Recall that a tree is a connected graph without cycles. Vertices 𝑢𝑖 and 𝑣𝑖 are connected by an edge with weight 𝑤𝑖.
You are given a tree, which consists of 𝑛 vertices. Recall that a tree is a connected undirected graph without cycles.
Example of a tree.
Vertices are numbered from 1 to 𝑛. All vertices have weights, the weight of the vertex 𝑣 is 𝑎𝑣.
Recall that the distance between two vertices in the tree is the number of edges on a simple path between them.