#K53867. Wizard Spell Strength
Wizard Spell Strength
Wizard Spell Strength
You are given a set of n islands connected by m bidirectional bridges. Each bridge is characterized by its strength value. Among these islands, a subset contains wizard towers. A spell starts at one wizard tower island, travels to another island (which may or may not contain a wizard tower) along a simple path, and then returns to a (different) wizard tower island along the same route in reverse. The remaining strength of the spell is defined as twice the minimum bridge strength along the chosen path. Formally, if a path uses bridges with strengths \(s_1, s_2, \dots, s_k\), then the remaining strength is \(2\min(s_1,s_2,\dots,s_k)\).
Your task is to determine the maximum remaining spell strength over all valid round trips between two distinct wizard tower islands. If no valid round trip exists (for example, if there is less than two wizard tower islands or no path connects any two distinct wizard islands), output -1.
Note: The bridges are bidirectional and there may be multiple ways to travel between islands. The input guarantees that each bridge connects two distinct islands.
Input Format (see below):
- The first line contains three integers: n (number of islands), m (number of bridges), and t (number of wizard islands).
- The next m lines each contain three integers: a, b, and s, representing a bridge between islands a and b with strength s.
- The last line contains t space‐separated integers indicating the island numbers that have wizard towers. When t is 0, this line will be empty.
Output Format:
Output a single integer representing the maximum remaining spell strength (i.e. \(2\times\text{(bottleneck)}\)) for any valid round trip. If no such trip exists, output -1.
inputFormat
The input is given via stdin in the following format:
n m t a1 b1 s1 a2 b2 s2 ... am bm sm w1 w2 ... wt
where the integers denote: n islands, m bridges, and t wizard tower islands followed by m lines of bridge descriptions and one line of wizard island indices. (If t is 0, the last line will be blank.)
outputFormat
The output (via stdout) should be a single integer — the maximum remaining spell strength according to the criteria described, or -1 if no valid spell can be cast.
## sample5 6 2
1 2 5
2 3 1
3 4 1
4 5 10
1 3 2
2 4 3
1 2
10
</p>