Dueling GPSs

No attempts yetTime limit1sMemory limit128 MB

Problem

Farmer John accidentally ordered two GPS units for his new car. Both use the same map, but each assigns its own travel time to every road.

The map has NN intersections (2N100002 \le N \le 10\,000) and MM one-way roads (1M500001 \le M \le 50\,000). Road ii runs from AiA_i to BiB_i. Multiple roads may connect the same pair of intersections, and a two-way road appears as two opposite one-way roads. FJ's house is at intersection 1 and his farm at intersection NN. The farm is reachable from the house.

Road ii takes PiP_i time according to the first GPS and QiQ_i time according to the second (each is an integer in 11000001 \ldots 100\,000).

When FJ travels from his house to the farm, a GPS complains whenever he uses a road that it does not consider part of any shortest route from the current intersection to the farm. If both GPS units complain on the same road, that adds 2 to the total.

Find the minimum total number of complaints over all routes from 1 to NN.

Input

  • Line 1: NN and MM.
  • Next MM lines: AiA_i, BiB_i, PiP_i, QiQ_i.

Output

The minimum total number of complaints.

Hint

Precompute shortest distances to the farm for each GPS, then mark roads that are not on any shortest-path edge as complaints.