This page is still under construction.

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

Ceste

Time limit2.5sMemory limit128 MB

Summary
For each city, find the route from city 1 that minimizes the product of total travel time and total cost, or report -1 if unreachable.
Level

Hard8 of 10

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

Problem

A country has NN cities and MM two-way roads. Driving along road ii takes TiT_i minutes and costs CiC_i kuna. Kuna is the currency of Croatia.

You start in city 11. For a route, the total time is the sum of TiT_i over the roads you drive along, and the total cost is the sum of CiC_i over the same roads. The value of a route is its total time multiplied by its total cost.

For every city other than city 11, find the smallest value among all routes from city 11 to that city. If no such route exists, print −1-1.

Input

The first line contains the number of cities NN (1≤N≤20001 \le N \le 2000) and the number of roads MM (1≤M≤20001 \le M \le 2000).

Each of the next MM lines contains four integers AiA_i, BiB_i, TiT_i, CiC_i (1≤Ai,Bi≤N1 \le A_i, B_i \le N, 1≤Ti,Ci≤20001 \le T_i, C_i \le 2000). They mean that a road connects city AiA_i and city BiB_i, and driving along it takes TiT_i minutes and costs CiC_i kuna.

Two cities can be connected by more than one road. No road connects a city to itself.

Output

Print N−1N - 1 lines. On line ii, print the smallest value among all routes from city 11 to city i+1i + 1. If the two cities are not connected, print −1-1.

Hint

Consider the second example.

To reach city 22 you drive along road 11. It takes 11 minute and costs 77 kuna, so the value is 77.

To reach city 33 you drive along road 22. It takes 33 minutes and costs 22 kuna, so the value is 66.

To reach city 44 you drive along roads 22, 44 and 55 in that order. Together they take 1111 minutes and cost 44 kuna, so the value is 4444.

Examples3

  1. Example 1

    Input
    4 4
    1 2 2 4
    3 4 4 1
    4 2 1 1
    1 3 3 1
    
    Expected output
    8
    3
    14
    
  2. Example 2

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

    Input
    3 2
    1 2 2 5
    2 1 3 3
    
    Expected output
    9
    -1