[Solution] Energetic Node(Easy Version) CodeChef Solution
Problem
This is the easy version of the problem. The only difference is that, in this version, .
There’s a tree having nodes, out of which, some nodes are energetic.
Initially, energy of all the nodes is . In the second, every energetic node will make the energy of itself and all its neighbours increase by .
You need to answer queries. For the query, you are given three integers:
- : Find the minimum number of seconds after which, there are at least nodes with energy not less than on the path from node to node . If it is not possible to have at least nodes with energy not less than on the path from node to node after any amount of time, print instead.
Input Format
- The first line contains an integer — the number of nodes.
- The second line contains space-separated integers, the array denoting whether the nodes are energetic. If , it means that the node is energetic, otherwise the node is not energetic.
- The next lines describe the edges. The of these lines contains two space-separated integers and , denoting an edge between and .
- The next line contains an integer — the number of queries.
- The next lines contain three space-separated integers , the query.
Output Format
For each query, output on a new line: the minimum number of seconds after which, there are at least nodes with energy not less than on the path from node to node .
If it is not possible to have at least nodes with energy not less than on the path from node to node after any amount of time, print instead.
Explanation:
Query : No matter how long, there will not be at least nodes having energy not less than on the path from node to node . Thus, the answer is .
Query : In the second, the energy of nodes and becomes and respectively. Thus, there are at least nodes with energy not less than .
Query : In the second, the energy of nodes and becomes and respectively. Thus, there are at least nodes with energy not less than .
Query : In the second, the energy of nodes and is and respectively. Thus, there are at least nodes with energy not less than .
No comments:
Post a Comment