cho.sh
Notes
Loading...

Highway

Time limit

2s

Memory limit

128 MB

Problem

There is an undirected highway network connecting several cities. Each road has a toll and a travel time.

For a route from the start city to the destination city, the total toll is the sum of the tolls of the used roads, and the total time is the sum of their travel times. A route A is better than a route B if A's total toll is no greater than B's total toll, A's total time is no greater than B's total time, and at least one of the two values is smaller.

A toll-time pair is efficient if some route produces that pair and no other route is better than it. If multiple routes produce the same toll-time pair, count that pair only once.

Given the highway network, the start city, and the destination city, find the number of distinct efficient toll-time pairs for routes from the start city to the destination city.

Input

The first line contains the number of cities n, the number of roads m, the start city s, and the destination city e.

  • 1 <= n <= 100
  • 1 <= m <= 300
  • 1 <= s, e <= n
  • s != e

Each of the next m lines describes one road. A line contains the two endpoint cities p and r, the toll c, and the travel time t.

  • 1 <= p, r <= n
  • p != r
  • 0 <= c <= 100
  • 0 <= t <= 100

There may be more than one road between the same two cities.

Output

Print the number of distinct efficient toll-time pairs for routes from the start city to the destination city.