This page is still under construction.

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

Shopping Malls

Interview

Time limit1sMemory limit128 MB

Summary
Given a connected weighted graph with some cities holding malls, find the maximum over all points on roads of the distance to the nearest mall, then round to the nearest integer.
Level

Medium6 of 10

Topics
Shortest path, Graph, Greedy, Math
Solved
No attempts yet

Problem

A country has NN cities connected by MM bidirectional roads. Exactly KK of these cities contain a shopping mall, and residents travel along the roads to a city with a mall in order to shop.

A house may sit inside a city, or at any point along a road. The distance from a house to the malls is defined as the shortest distance from that house to the nearest mall. People always take a shortest path, and moving within a city takes 00 time.

Given the roads and the cities that contain a mall, write a program that finds the distance to the house that is farthest from the malls — that is, the maximum, over every possible house location, of the shortest distance from that house to the nearest shopping mall.

Input

The first line contains the number of cities NN, the number of roads MM, and the number of cities that contain a mall KK. Cities are numbered from 11 to NN. (2≤N≤30002 \le N \le 3000, 1≤M≤1051 \le M \le 10^5, 1≤K≤N1 \le K \le N)

Each of the next MM lines contains a road aa, bb, ll: a road of length ll (1≤l≤10001 \le l \le 1000) connecting city aa and city bb. aa and bb are different, and at most one road connects any pair of cities. Every city is reachable from every other city (the graph is connected).

Each of the next KK lines contains the number of one city that has a mall, one per line; these numbers are distinct.

Output

Print the distance to the house that is farthest from the malls, rounded to the nearest integer (round halves up).

Hint

Suppose a house lies on the road of length ll between city aa and city bb, at distance xx (0≤x≤l0 \le x \le l) from city aa. Then the distance from this house to the nearest mall is min⁡(da+x,  db+(l−x))\min(d_a + x,\; d_b + (l - x)), where dvd_v is the shortest distance from city vv to the nearest mall. The point that maximizes this value gives a distance of da+db+l2\dfrac{d_a + d_b + l}{2}.

In the first example, every road has length 11 and the only mall is in city 11. The house farthest from the mall lies on the road between city 22 and city 33, at distance 0.50.5 from city 22; its distance to the mall is 1.51.5, which rounds to 22.

Examples2

  1. Example 1

    Input
    3 3 1
    1 2 1
    2 3 1
    3 1 1
    1
    
    Expected output
    2
    
  2. Example 2

    Input
    4 5 2
    1 2 4
    1 3 1
    2 3 2
    2 4 2
    3 4 1
    2
    4
    
    Expected output
    3