This page is still under construction.

Parts of this page are still being built. What you see may change.

Trucking Troubles

Time limit1sMemory limit128 MB

Summary
Find the maximum weight W such that keeping only bridges with capacity at least W still lets city 1 reach every destination city.
Level

Medium6 of 10

Topics
Union-find, Graph, Sorting, Greedy
Solved
No attempts yet

Problem

You sell trucks that can carry trucks that can carry trucks, so your trucks are extremely heavy. To deliver one, you must drive it across a wide, wet region, and because it is wet you have to cross bridges along the way.

The region has cc cities, numbered from 11 to cc. Between some pairs of cities there is a road, and every road carries a bridge — but not every pair of cities is connected by a direct road. Each bridge has a maximum weight capacity, an integer from 00 to 100 000100\,000; a truck may cross a bridge only if the truck's weight does not exceed that capacity.

Some cities are destination cities, where customers are eager to see your truck. You start at city 11 (which is never a destination city) and must visit all dd destination cities, in any order. Because you drive a single truck, its weight is fixed for the whole journey.

Determine the maximum truck weight for which you can start at city 11 and still reach every destination city, using only bridges that can support that weight.

Input

The first line contains three positive integers cc, rr, and dd: the number of cities, the number of roads, and the number of destination cities. There are at most 10 00010\,000 cities and at most 100 000100\,000 roads.

Each of the next rr lines contains three integers x y wx\ y\ w, meaning there is a road between city xx and city yy whose bridge has a maximum weight capacity of ww.

Each of the next dd lines contains one destination city. There is at least one destination city, and city 11 is never a destination.

Output

Print a single integer: the largest weight that can be driven from city 11 through all dd destination cities.

Examples2

  1. Example 1

    Input
    5 7 3
    1 2 20
    1 3 50
    1 4 70
    1 5 90
    2 3 30
    3 4 40
    4 5 60
    2
    4
    5
    
    Expected output
    30
    
  2. Example 2

    Input
    2 1 1
    1 2 42
    2
    
    Expected output
    42