Intercity
Time limit3sMemory limit128 MB
Find the cheapest fare from city 1 to city N in a complete graph where K given edges cost A and all other edges cost B.
- Level
Medium7 of 10
- Topics
- Shortest path, Graph, BFS
- Solved
- No attempts yet
Problem
A few years ago the Ukrainian railway system was very convenient. Between any two cities ran one direct train, and anyone could pay hryvnia to travel from the city they were in to the city they wanted to reach.
Recently a lot of new trains were launched. Each new train replaced one old train, and its fare was set to hryvnia. So between any pair of cities there is still exactly one direct train, either new or old. Every train runs in both directions, and the fare does not depend on the direction.
Ukraine has large cities and you live in city 1. You want to reach city as cheaply as possible. The number of transfers does not matter.
Input
The first line contains four integers , , , (, , ): the number of cities, the number of new trains, the fare of a new train and the fare of an old train.
Each of the next lines contains two integers and (), meaning that a new train runs between city and city . and are different, and every pair of cities appears at most once.
Output
Print the fare of the cheapest way to get from city 1 to city .