PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#LCA0000021. Thung lũng và các cửa hàng (Valley)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 nn locations connected by n−1n-1 bidirectional roads of positive length, forming a tree. Location EE is the exit; SS locations have supply shops.

Each of QQ independent scenarios specifies a road index II that is blocked and a starting location RR. If you can reach the exit EE without using road II, output escaped. Otherwise, find the shortest distance from RR 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 n,S,Q,En,S,Q,E.
  • The next n−1n-1 lines list road ii as ai,bi,wia_i,b_i,w_i.
  • The next SS lines each contain the location index of one shop.
  • The final QQ lines contain blocked road index II and starting location RR.

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): n≤30n\le30; Q≤60Q\le60; 2≤n≤1052\le n\le10^5; 1≤S≤n1\le S\le n; 1≤Q≤1051\le Q\le10^5; 1≤E,R≤n1\le E,R\le n; 1≤wi≤1091\le w_i\le10^9; 1≤I≤n−11\le I\le n-1.
  • Subtask 2 (30 points): n≤1000n\le1000; Q≤3000Q\le3000; 2≤n≤1052\le n\le10^5; 1≤S≤n1\le S\le n; 1≤Q≤1051\le Q\le10^5; 1≤E,R≤n1\le E,R\le n; 1≤wi≤1091\le w_i\le10^9; 1≤I≤n−11\le I\le n-1.
  • Subtask 3 (50 points): 2≤n≤1052\le n\le10^5; 1≤S≤n1\le S\le n; 1≤Q≤1051\le Q\le10^5; 1≤E,R≤n1\le E,R\le n; 1≤wi≤1091\le w_i\le10^9; 1≤I≤n−11\le I\le n-1.

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 22 blocked, starting at 22 still permits reaching the exit: escaped. Starting at 55 instead leaves the closest shop at distance 33. Blocking road 44 and starting at 55 leaves no reachable shop: oo.