Ceste
Time limit2.5sMemory limit128 MB
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 cities and two-way roads. Driving along road takes minutes and costs kuna. Kuna is the currency of Croatia.
You start in city . For a route, the total time is the sum of over the roads you drive along, and the total cost is the sum of over the same roads. The value of a route is its total time multiplied by its total cost.
For every city other than city , find the smallest value among all routes from city to that city. If no such route exists, print .
Input
The first line contains the number of cities () and the number of roads ().
Each of the next lines contains four integers , , , (, ). They mean that a road connects city and city , and driving along it takes minutes and costs kuna.
Two cities can be connected by more than one road. No road connects a city to itself.
Output
Print lines. On line , print the smallest value among all routes from city to city . If the two cities are not connected, print .
Hint
Consider the second example.
To reach city you drive along road . It takes minute and costs kuna, so the value is .
To reach city you drive along road . It takes minutes and costs kuna, so the value is .
To reach city you drive along roads , and in that order. Together they take minutes and cost kuna, so the value is .