Vera and the Engineering Buildings
Time limit2sMemory limit512 MB
Given a tree of N nodes with distinct hidden values and inspection costs, find the minimum total cost of an adaptive strategy that is guaranteed to locate a local maximum.
- Level
Hard8 of 10
- Topics
- Tree, Dynamic programming, Game theory, Bit manipulation
- Solved
- No attempts yet
Problem
The University of Waterloo has engineering buildings numbered from 1 to . For every with there is a two way bridge between building and building . Two buildings are neighbours when a bridge joins them.
Every building has its own aesthetic value, and no two buildings share a value. A value can be any integer. Measuring a value exactly is hard, so Vera only wants to find one nice building, a building whose aesthetic value is higher than the value of each of its neighbours.
Inspecting building takes seconds and covers the bridges to all of its neighbours. Once the inspection is over, Vera knows for each neighbour of building which of building and building has the higher aesthetic value.
Vera picks the next building to inspect after seeing the results of the earlier inspections. Travel time between buildings is ignored. Find the smallest total inspection time that guarantees Vera finds a nice building, whatever the aesthetic values are.
Input
The first line contains one integer ().
The second line contains integers ().
The third line contains integers ().
Output
Print one line with one integer, the minimum total number of seconds that guarantees a nice building is found.
Hint
In the first example, inspecting buildings 1 and 3 guarantees a nice building is found.
In the second example, one optimal strategy always inspects building 3 first.