#LCA0000021. Thung lũng và các cửa hàng (Valley)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Thung lũng và các cửa hàng (Valley)
Valley
Source: Baltic Olympiad in Informatics
Version: Phuoc Hung OJ Extended
Problem Statement
A valley contains locations connected by bidirectional roads of positive length, forming a tree. Location is the exit; locations have supply shops.
Each of independent scenarios specifies a road index that is blocked and a starting location . If you can reach the exit without using road , output escaped. Otherwise, find the shortest distance from to any shop still reachable without the blocked road.
If you cannot escape and cannot reach any shop, output oo. Road closures are independent across scenarios.
Input
- The first line contains .
- The next lines list road as .
- The next lines each contain the location index of one shop.
- The final lines contain blocked road index and starting location .
Output
For every scenario print escaped if the exit is reachable; otherwise print the distance to the closest reachable shop, or oo if none is reachable.
Subtasks
- Subtask 1 (20 points): ; ; ; ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; ; ; ; .
- Subtask 3 (50 points): ; ; ; ; ; .
Examples
Input
5 2 3 1
1 2 3
1 3 2
3 4 1
3 5 2
2
4
2 2
2 5
4 5
Output
escaped
3
oo
Explanation
With road blocked, starting at still permits reaching the exit: escaped. Starting at instead leaves the closest shop at distance . Blocking road and starting at leaves no reachable shop: oo.