Turtle Elder
InterviewTime limit5sMemory limit256 MB
Pick safe start and end islands in a tree so the sum of values along the path is as large as possible, staying home when the best sum is not positive.
- Level
Medium4 of 10
- Topics
- Tree, Dynamic programming
- Solved
- No attempts yet
Problem
N islands form a tree. Touching island i changes lifespan by days. Some islands are unsafe for landing or signaling. With only one flare, choose safe entry and exit islands to maximize lifespan gain. If the best gain is not positive, print Stay Home.
Input
The first line contains test cases (). Each test case gives , bridges, array , and a safe/island mask.
Output
Print the maximum lifespan gain, or Stay Home if it is not positive.