Under construction

Still being built. Things may change

WALK

Time limit1.5sMemory limit1024 MB

Summary
Given streets each with a recorded traversal time, find the longest walk from crossroad 1 to every crossroad where the times strictly increase.
Level

Medium5 of 10

Topics
Dynamic programming, Graph, Sorting
Solved
No attempts yet

Problem

Who doesn't love walks?

The map of Shumen is a set of NN crossroads numbered from 1 to NN, joined by MM bidirectional streets numbered from 1 to MM. Each street joins two different crossroads, and no two crossroads are joined by more than one street. Any crossroad can be reached from any other by following the streets.

Kyusho and his dog Bobby went on a night walk the night before yesterday's party. They traversed every one of the MM streets at least once. Bobby is exceptionally intelligent but has trouble remembering the order of the streets, so his memory is chaotic and sometimes contradictory. For example, the dog may remember that some street was traversed at moment 10 while no street is remembered at moment 9. Formally, Bobby remembers that the ii-th street, between crossroads aia_i and bib_i, was traversed at moment cic_i.

The next morning Kyusho realized that he also has trouble remembering that night, so he wants to reconstruct the walk as well as he can. He starts a new walk at his hotel, crossroad 1. Each street he traverses must have a later moment (by Bobby's memory) than the street before it, that is, cnext>ccurrentc_{next} > c_{current}. He may pass through a crossroad more than once.

He wants the new walk to be as long as possible, and he has not decided where it should end. For each crossroad, find the longest walk that ends there and follows the rule above. The length is the number of streets passed.

Input

The first line contains two integers NN and MM, the number of crossroads and the number of streets. Each of the next MM lines contains three integers aia_i, bib_i, and cic_i, which describe a street between crossroads aia_i and bib_i that was traversed at moment cic_i according to Bobby's memory.

Output

Print NN integers separated by spaces: the maximal lengths of walks from crossroad 1 to crossroads 1,2,…,N1, 2, \dots, N. If no walk reaches a crossroad, print 0 for it.

Constraints

2≤N≤1052 \le N \le 10^5, 1≤M≤1061 \le M \le 10^6, 1≤ai,bi≤N1 \le a_i, b_i \le N, ai≠bia_i \ne b_i, 1≤ci≤1091 \le c_i \le 10^9.

Hint

The figure below shows the streets and crossroads.

The optimal walk to crossroad 3 is 1−15−26−62−78−85−1031 \overset{1}{-} 5 \overset{2}{-} 6 \overset{6}{-} 2 \overset{7}{-} 8 \overset{8}{-} 5 \overset{10}{-} 3. At crossroad 8, we cannot continue to crossroad 7, because that street has moment 5, and we arrived through a street with moment 7.

Examples1

  1. Example 1

    Input
    8 12
    1 4 9
    1 6 4
    1 5 1
    3 4 11
    3 5 10
    5 6 2
    6 2 6
    2 8 7
    5 8 8
    7 8 5
    5 7 14
    3 7 12
    
    Expected output
    3 3 6 7 8 2 7 4