Police and Thief
Time limit1.5sMemory limit1024 MB
Given a tree of houses with road lengths, find how long a police officer at P (speed V1) takes to catch a thief starting at T (speed V2), for each of Q scenarios.
- Level
Hard8 of 10
- Topics
- Tree, Binary search, Shortest path
- Solved
- No attempts yet
Problem
KOI Village has houses and two-way roads connecting them. Any two different houses can reach each other using only roads. In other words, the road network of KOI Village forms a tree.
The houses are numbered differently from to , and the roads are numbered differently from to . For every , road connects house and house , and its length is meters.
Recently, thieves have often broken into KOI Village, and residents are having a hard time. To prepare for this, a police officer is posted at one house in KOI Village so they can respond when a thief appears. The residents want to know how quickly the police can catch a thief during a break-in.
You are given scenarios. The scenarios are numbered differently from to . Each scenario works as follows.
- In scenario , the police start at house and can move at most meters per second.
- In scenario , the thief starts at house and can move at most meters per second.
- The house where the police start and the house where the thief starts are different. That is, .
- Houses are treated as points because they are small enough. Roads are treated as line segments because they are narrow enough. Roads do not cross each other.
- The police and the thief can each move freely within KOI Village, up to their maximum speeds. Staying still is also allowed.
- If the police are at the same position as the thief, the police can catch the thief. The police can catch the thief not only at a house but also in the middle of a road.
- In a scenario, the police and the thief know their own speed and the other's speed, and at any moment they can know the other's position.
- The police and the thief use their best strategies. The police use the strategy that catches the thief fastest, and the thief uses the strategy that keeps running for the longest time. When both use their best strategies, it can be proven that the thief is caught in finite time.
For each scenario, find the time it takes for the police to catch the thief.
Constraints
- For all , and
- For all ,
- The road network of KOI Village forms a tree.
- For all , and
- For all ,