Under construction

Still being built. Things may change

Shelter

Time limit4sMemory limit1024 MB

Summary
Find the minimum time for every resident to reach a shelter along shortest paths, with each shelter holding at most its capacity.
Level

Medium7 of 10

Topics
Binary search, Shortest path, Bit manipulation
Solved
No attempts yet

Problem

In a dimly lit room, at about 23:55, Milan sits at a three-legged table and thinks about the possible consequences a nuclear disaster would have on his city. As mayor, he knows all the relevant facts well.

The city has exactly NN residents, and each resident lives in a house of their own. Exactly MM pairs of houses are connected by roads, and the time needed to travel each road is known. Exactly KK houses contain atomic shelters, and the capacity of each shelter is known. Milan keeps asking himself: "What is the minimum time needed to evacuate all residents of this city?"

Evacuation means that every resident ends up in some atomic shelter. Residents move optimally (along shortest paths), and several people may move along the same road at the same time in different directions. You may also assume that any two houses are connected by a path that uses some subset of the given roads.

Input

The first line contains natural numbers NN (1≤N≤1000001 \le N \le 100000), MM (1≤M≤3000001 \le M \le 300000), and KK (1≤K≤171 \le K \le 17), which are the number of residents, the number of roads, and the number of shelters. Houses are numbered from 1 to NN.

Each of the next MM lines contains three natural numbers AA, BB (1≤A,B≤N1 \le A, B \le N, A≠BA \ne B), and CC (1≤C≤1091 \le C \le 10^9). This means there is a road between houses AA and BB, and passing through it takes CC units of time.

Each of the next KK lines contains two natural numbers XX (1≤X≤N1 \le X \le N) and YY (1≤Y≤1091 \le Y \le 10^9). This means house XX has an atomic shelter that can hold at most YY people. The total capacity of all shelters is at least NN.

Output

Print one line with the minimum time needed to evacuate all residents of the city.

Hint

In the first sample, within 3 units of time, the people from houses 1, 2, and 3 can reach the shelter in house 1, and the people from houses 4 and 5 can reach the shelter in house 4. A shorter time is not enough for everyone to reach a shelter, because the shelter in house 4 holds at most two people.

Examples2

  1. Example 1

    Input
    5 5 2
    1 2 1
    1 3 3
    2 3 4
    3 4 1
    4 5 1
    1 10
    4 2
    
    Expected output
    3
    
  2. Example 2

    Input
    7 8 3
    1 2 5
    2 3 3
    3 4 5
    1 4 1
    4 5 7
    5 6 2
    6 7 1
    4 7 4
    3 3
    7 3
    6 2
    
    Expected output
    5