Baltic Olympiad in Informatics: 2002 Day 2, Problem 1
The network of pay highways in Byteland is growing up very rapidly. It has become so dense, that the choice of the best route is a real problem. The network of highways consists of bidirectional roads connecting cities. Each such road is characterized by the traveling time and the toll to be paid.
The route is composed of consecutive roads to be traveled. The total time needed to travel the route is equal to the sum of traveling times of the roads constituting the route. The total fee for the route is equal to the sum of tolls for the roads of which the route consists. The faster one can travel the route and the lower the fee, the better the route. Strictly speaking, one route is better than the other if one can travel it faster and does not have to pay more, or vice versa: one can pay less and can travel it not slower than the other one. We will call a route connecting two cities minimal if there is no better route connecting these cities. Unfortunately, not always exists one minimal route – there can be several incomparable routes or there can be no route at all.
Your task is to write a program which computes the number of different minimal routes connecting the starting and ending city, however all the routes characterized by the same fee and traveling time count as just one route; we are interested just in the number of different minimal pairs fee-time.
Constraints
,
,
Input Specification
There are four space-separated integers in the first line of input: the number of cities (they are numbered from to ), number of roads , starting city and ending city of the route.
The consecutive lines describe the roads, one road per line.
Each of these lines contains four space-separated integers: two ends of a road and , the toll , and the traveling time . Two cities can be connected by more than one road.
Output Specification
Your program should output one integer on the only line of output: the number of different minimal pairs fee-time for routes from to .
Sample Input
4 5 1 4
2 1 2 1
3 4 3 1
2 3 1 2
3 1 1 4
2 4 2 4
Sample Output
2
Sample Explanation
The picture below presents the example network of highways. Each road is accompanied by a pair of numbers: the toll and the traveling time.
Let us consider four different routes from city to city , together with their fees and traveling times: (fee , time ), (fee , time ), (fee , time ) and (fee , time ).
Routes and are better than . There are two minimal pairs fee-time: fee , time (roots and ) and fee , time (root ). When choosing the route we have to decide whether we prefer to travel faster but we must pay more (route ), or we would rather travel slower but cheaper (route or ).
Comments