Under construction

Still being built. Things may change

Copogonia

Time limit2sMemory limit1024 MB

Summary
Given a convex polygon of n cities and up to k candidate chords with costs, choose a cheapest subset so every pair of cities has shortest route length at most m.
Level

Hard8 of 10

Topics
Bit manipulation, Shortest path, Brute force, Graph
Solved
No attempts yet

Problem

Copogonia is a country with a set of nn cities, which currently has nn roads. The roads form a convex polygon, hence the name of the country. There are always exactly two ways to travel between any pair of distinct cities (clockwise or counter-clockwise). For some pairs, even the shorter of the two routes takes too long.

A survey found that citizens are happy only if no route between any two cities has length greater than mm. In other words, the path between any two cities must have length mm or less.

The government may build up to kk new roads. Each new road connects two cities that are not already directly connected, and its length must equal the straight-line distance between those two cities. Each road has a construction cost. Find the minimum total cost of a subset of roads that keeps all citizens happy.

Input

The first line contains three integers nn, kk, and mm (4≤n≤504 \le n \le 50, 1≤k≤101 \le k \le 10, mm is the maximum allowed travel distance). Each of the next nn lines contains two integers xix_i and yiy_i (0≤xi,yi≤1040 \le x_i, y_i \le 10^4), the coordinates of city ii. There is a road from city ii to city i+1i+1 for 1≤i≤n−11 \le i \le n-1, and a road from city nn to city 11. Roads can be traveled in either direction.

The next kk lines each contain three integers uu, vv, and cc (1≤u,v≤n1 \le u, v \le n, u≠vu \ne v, 1≤c≤1081 \le c \le 10^8). A road between uu and vv can be built at cost cc. No two cities are at the same location. No two candidate roads connect the same pair of cities, and no candidate connects two cities that already have a road.

At least one road must be built. Building all candidate roads makes all routes at most mm. Changing mm by 0.0010.001 does not change the answer.

Output

Print the minimum cost of a set of roads that keeps all citizens happy.

Examples2

  1. Example 1

    Input
    4 2 15
    0 0
    0 10
    10 10
    10 0
    1 3 1000
    2 4 500
    
    Expected output
    1500
    
  2. Example 2

    Input
    5 3 2003
    0 0
    0 100
    1000 100
    2000 99
    1000 0
    2 4 50
    4 1 123
    3 5 47
    
    Expected output
    170