#P5845. Escape Plan
Escape Plan
Escape Plan
Archaeologist Benjamas has been trapped in a mysterious underground crocodile palace after exploring its secret crocodile lair. The palace consists of \(N\) caves (numbered from 0 to \(N-1\)) and \(M\) bidirectional corridors. Each corridor connects two distinct caves and has a positive travel time. There is at most one corridor between any two caves. Among these \(N\) caves, \(K\) are exit caves through which Benjamas can immediately escape.
Benjamas starts at cave 0 and wants to escape as soon as possible. However, a crocodile guard is intent on stopping her. The guard can block any one corridor at any time (note that at any one time, only one corridor is blocked; if the guard blocks a new corridor, the previously blocked corridor immediately reopens). The escape process is described as follows:
- Whenever Benjamas tries to leave a cave, the guard will block exactly one corridor that is connected to that cave.
- Benjamas can only choose a corridor that is not blocked to move to the next cave. Once she enters a corridor, the guard cannot block it until she reaches the other end.
- When she arrives at the next cave, the guard can then block one of the corridors connected to that cave (which could include the corridor she just used).
Benjamas wants to design an escape plan. More precisely, she wishes to specify a set of instructions such that:
- If cave \(A\) is an exit cave, then no instruction is necessary because she can escape immediately.
- If cave \(A\) is not an exit, an instruction for cave \(A\) is of the following form: at cave \(A\), first try to take the corridor that leads to cave \(B\). If that corridor is blocked then take the corridor that leads to cave \(C\) (with \(B\) and \(C\) being distinct neighboring caves of \(A\)).
- Caves that are never reached by the escape plan do not require instructions.
The guard, aiming to delay her, may choose to block the corridor which maximizes her escape time. Let \(T\) be defined as the minimum worst-case escape time among all possible escape plans. In other words, for any cave \(A\) (which is not an exit) the escape plan assigns two outgoing corridors. If we denote by \(f(A)\) the worst-case time needed from cave \(A\) when following the plan, then for an exit cave \(E\) we have \(f(E)=0\) and for any other cave \(A\) the following recurrence holds: \[ f(A) = \min_{\substack{B,\,C \in \mathrm{Adj}(A),\\ B \neq C}} \; \max\{w(A,B)+f(B),\; w(A,C)+f(C)\}\,. \] Your task is to compute \(T=f(0)\). It is guaranteed that no matter how the guard blocks corridors, there exists an escape plan that guarantees Benjamas will reach an exit in finite time.
inputFormat
The first line contains three integers \(N\), \(M\) and \(K\) (where \(2 \le N \le 1000\), \(1 \le M \le 5000\), \(2 \le K \le N\)).
The second line contains \(K\) distinct integers representing the indices of the exit caves.
Each of the next \(M\) lines contains three integers \(u\), \(v\) and \(w\) (with \(0 \le u, v < N\) and \(u \neq v\)), meaning there is a corridor between caves \(u\) and \(v\) with travel time \(w\) (\(1 \le w \le 10^6\)). It is guaranteed that there is at most one corridor between any two caves.
outputFormat
Output a single integer \(T\), the minimum worst-case escape time from cave 0 if an optimal escape plan is followed. It is guaranteed that an escape plan exists.
sample
3 2 2
1 2
0 1 5
0 2 7
7