City Brain
Time limit4sMemory limit1024 MB
Given an undirected road graph, spend up to k dollars to raise road speeds so the sum of two shortest travel times, for two pairs of cities, is minimized.
- Level
Hard8 of 10
- Topics
- Graph, Shortest path, Brute force
- Solved
- No attempts yet
Problem
Prof. Pang works for the City Brain program of Capital Grancel. The road network of Grancel is an undirected graph. Initially, the speed limit on each road is m/s. Prof. Pang can raise the speed limit on a road by m/s for dollar. He has dollars and may spend any nonnegative integer amount on each road.
If a road has speed limit m/s, anyone can cross it in either direction in seconds. After Prof. Pang spends his money, Prof. Du travels from to , and Prof. Wo travels from to . Prof. Pang must spend the money so that the sum of the minimum travel times of Prof. Du and Prof. Wo is as small as possible.
It is guaranteed that and are connected by at least one path, and that and are connected by at least one path.
Input
The first line contains three integers , , and (, , ), separated by single spaces. Here is the number of vertices, is the number of edges, and is the number of dollars.
Each of the next lines contains two integers and (, ), the endpoints of one road. Multiple roads may connect the same pair of cities.
The last line contains four integers , , , and (), the start and end vertices of Prof. Du and Prof. Wo.
Output
Print one real number on a single line: the minimum sum of Prof. Du's and Prof. Wo's travel times. The answer is accepted if its absolute or relative error does not exceed .