This page is still under construction.

Parts of this page are still being built. What you see may change.

Cows Drive

Time limit0.5sMemory limit1024 MB

Summary
For each city, find the minimum travel time from city 1 minus the taste value of one rest stop chosen on the path.
Level

Medium7 of 10

Topics
Graph, Shortest path, Heap, Dynamic programming
Solved
No attempts yet

Statement

The cows decided to just drive instead of flying. In the country where they live, there are VV cities and EE bidirectional highways connecting pairs of cities. The cows live in city 11, where Sunlin Internet High School is. Oh, and here is a tip: in the middle of every highway there is a rest stop that sells tonkatsu.

Vacation season has arrived and the cows set off on a trip. As you know, Bessie the cow wants to travel to another city. Bessie will ride the highways appropriately to reach her destination. Choose the route well and find the minimum time needed to travel from city 11 to the city Bessie will visit. Oh, which city she will visit is a secret. So for each city from 22 to NN, find the minimum time needed to travel from city 11 to that city.

... But Bessie suddenly feels empty. She has learned that this problem is far too easy to solve with Dijkstra's algorithm, and she has also realized her own desire to eat the tonkatsu sold at the highway rest stops. Bessie surveyed every tonkatsu at every highway and recorded a numeric value for its taste. On the route she takes for her vacation, Bessie will stop at exactly one of the rest stops and buy tonkatsu to eat. For each city from 22 to NN that Bessie can visit, choose the route and the rest stop to visit well, and find the minimum value of the time needed to travel from city 11 to that city minus the taste of the tonkatsu she eats after appropriately stopping at one rest stop along the way. Of course, the time spent eating tonkatsu is not included in the travel time.

Input

The first line gives the number of cities in the country, VV, and the number of highways, EE.

From the second line, EE lines give information about each highway. Each line gives the two cities xx and yy that the highway connects, the time tt needed to travel from xx to yy, and the value kk representing the taste of the tonkatsu sold at the rest stop, in that order, separated by spaces.

There are no two or more highways connecting the same pair of cities. All cities are connected directly or indirectly through the highways.

Output

Print V−1V-1 integers in total, one per line. The ii-th integer printed is the minimum value of the time needed to travel from city 11 to city i+1i+1 minus the taste of the tonkatsu eaten along the way.

Constraints

  • 1≤V≤100,0001 \le V \le 100,000
  • 1≤E≤100,0001 \le E \le 100,000
  • 1≤x≠y≤V1 \le x \neq y \le V
  • 1≤t≤20,0001 \le t \le 20,000
  • 1≤k≤1,000,000,0001 \le k \le 1,000,000,000

Examples2

  1. Example 1

    Input
    4 5
    1 2 2 1
    2 3 3 2
    2 4 4 3
    1 3 6 2
    4 3 3 4
    
    Expected output
    1
    3
    3
    
  2. Example 2

    Input
    4 4
    1 2 4 10
    1 3 4 2
    2 4 4 3
    3 4 4 1
    
    Expected output
    -6
    2
    -2