Olympic Airlines
The Emperor of Olympia has decided to connect N cities within the empire using air transport. The court programmer has been assigned the task of developing a program named OlympBuild to streamline the creation of a flight map. This program must handle two types of operations, each involving three parameters: A, B, and C:
Establish a new flight from city A to city B, with a duration of C minutes.
For all flights originating from city A, let flight number i terminate at city v_i and take t_i minutes. For each such i, create a flight from city B to city v_i, with a duration of t_i + C minutes.
After executing all operations, the program must determine the shortest time required to fly from the capital to each city, potentially involving transfers at other cities. It is assumed that boarding, disembarking, and waiting times at airports are zero.
There can be multiple flights between two cities, each with different durations. Flights may also start and end in the same city. All flights are one-way, meaning a direct flight from city A to city B does not imply a direct flight from city B to city A.
Write a program that, given a sequence of M operations as described above, executed by the OlympBuild program, finds the shortest time required to fly from the capital to each city, except the capital itself.
Input
The first line contains two integers N and M (2 ≤ N ≤ 10^5, 1 ≤ M ≤ 10^5)—the number of cities in the Olympia empire and the number of operations performed by the OlympBuild program. Each of the following M lines contains details of an operation. The first number in the line is 1 if the operation is of the first type, and 2 if it is of the second type. This is followed by three integers A, B, and C (1 ≤ A ≤ N, 1 ≤ B ≤ N, -10^8 ≤ C ≤ 10^8), as described above. Cities are numbered from 1 to N, with the capital being city 1. It is guaranteed that the flight time for each flight will be strictly positive.
Output
Output N - 1 lines. In the i-th line, provide the shortest time in minutes to fly from the capital to the city numbered i + 1. If a city is unreachable, output the number -1 for that city.