Copogonia
Time limit2sMemory limit1024 MB
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 cities, which currently has 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 . In other words, the path between any two cities must have length or less.
The government may build up to 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 , , and (, , is the maximum allowed travel distance). Each of the next lines contains two integers and (), the coordinates of city . There is a road from city to city for , and a road from city to city . Roads can be traveled in either direction.
The next lines each contain three integers , , and (, , ). A road between and can be built at cost . 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 . Changing by does not change the answer.
Output
Print the minimum cost of a set of roads that keeps all citizens happy.