Archaeologist Benjamas is running for her life after investigating the mysterious Crocodile's Underground City. The city has chambers. There are bidirectional corridors, each connecting a different pair of distinct chambers. Running through different corridors may require different amounts of time. Only of the chambers are exit chambers that allow her to escape. Benjamas starts in chamber . She wants to reach an exit chamber as quickly as possible.

The Crocodile gatekeeper wants to prevent Benjamas from escaping. From his den, he controls secret doors that can block any *single* corridor. That is, whenever he blocks a new corridor, the previously blocked one has to be reopened.

Benjamas's situation can be described as follows: Each time she tries to leave a chamber, the Crocodile gatekeeper may choose to block one of the corridors adjacent to it. Benjamas then chooses and follows one of the unblocked corridors to the next chamber. Once Benjamas enters a corridor, the Crocodile gatekeeper may not block it until Benjamas reaches the other end. Once she enters the next chamber, the gatekeeper may again choose to block one of the outgoing corridors (possibly the corridor that Benjamas just followed), and so on.

She would like to have a simple escape plan in advance. More precisely, she would like to have a set of instructions that tell her what to do when she gets to a chamber. Let be one of the chambers. If it is an exit chamber, no instructions are needed–obviously, she can escape the city. Otherwise, the instruction for chamber should have one of the following forms:

- "If you ever reach chamber , take the corridor leading to chamber . However, if that corridor is blocked, then take the corridor leading to chamber ."
- "Don't bother about chamber ; according to this escape plan you cannot possibly reach it."

Note that in some cases (for example, if your plan directs Benjamas to run in a cycle) the gatekeeper may be able to prevent Benjamas from reaching an exit. An escape plan is *good* if Benjamas is guaranteed to reach an exit chamber after a finite amount of time, regardless of what the gatekeeper does. For a good escape plan, let be the smallest time such that after time , Benjamas is *guaranteed* to reach an exit. In that case, we say that *the good escape plan takes time* .

#### Your task

Write a procedure `travel_plan(N, M, R, L, K, P)`

that takes the following parameters:

- – the number of chambers. The chambers are numbered through .
- – the number of corridors. The corridors are numbered through .
- – a two-dimensional array of integers representing the corridors. For , corridor connects two distinct chambers and . No two corridors join the same pair of chambers.
- – a one-dimensional array of integers containing the times needed to traverse the corridors. For , the value is the time Benjamas needs to runthrough the corridor.
- – the number of exit chambers. You may assume that .
- – a one-dimensional array of integers with distinct entries describing the exit chambers. For , the value is the number of the exit chamber. Chamber will never be one of the exit chambers.

Your procedure must return the smallest time for which there exists a good escape plan that takes time .

You may assume that each non-exit chamber will have at least two corridors leaving it. You may also assume that in each test case there is a good escape plan for which .

#### Examples

##### Example 1

Consider the case shown in Figure 1, where , , , and

Chambers are shown as circles, and corridors connecting them are shown as lines. Exit chambers are shown as thick-bordered circles. Benjamas starts at chamber . An optimal escape plan is the following one:

- If you ever reach chamber , take the corridor leading to chamber . However, if that corridor is blocked, then take the corridor leading to chamber .
- If you ever reach chamber , take the corridor leading to chamber . However, if that corridor is blocked, then take the corridor leading to chamber .

In the worst case, Benjamas will reach an exit chamber in 7 units of time. Hence, `travel_plan`

should return .

##### Example 2

Consider the case shown in Figure 2, where , , , and

Here is an optimal escape plan:

- If you ever reach chamber , take the corridor leading to chamber . However, if that corridor is blocked, then take the corridor leading to chamber .
- Don't bother about chamber ; according to this escape plan you cannot possibly reach it.

Benjamas will reach one of the exit chambers no later than after units of time. Therefore, `travel_plan`

should return .

#### Subtasks

##### Subtask 1 (46 points)

- The underground city is a tree. That is, and for each pair of chambers and there is a sequence of corridors connecting and .
- Every exit chamber is connected to exactly one other chamber.
- Any other chamber is connected directly to three or more other chambers.

## Comments