walk

Time limit: 1.5s Memory limit: 512MB Input: Output:

Who doesn't love walks?

The map of Shumen can be represented as NN crossroads, numbered with the integers from 11 to NN with MM bidirectional streets between them, numbered with the integers from 11 to MM. Every street connects a pair of different crossroads, and there isn't a pair of crossroads that are connected by two different streets. One could get from any crossroad to any other by traversing through the given streets.

Kyushо and his dog Bobby were having a night walk right before yesterday's party. They traversed all the MM streets at least once in the walk. Bobby, the dog, is exceptionally intelligent but has problems memorizing the order of the traversed streets and that's why it memorized them rather chaotically and sometimes even contradictory. For example, it is possible that for some street the dog has memorized that is was traversed at moment 1010 but there is no street that was memorized being traversed at moment 99. Formally, Bobby, the dog, has memorized that the ii-th street between crossroads aia_i and bib_i was traversed at moment cic_i.

In the morning, Kyusho realized that he also has problems remembering last night and wanted to recall the traversed crossroads from the walk as best as possible. To do this, he will take another walk, starting from his hotel in crossroad 11. As he does not want to get lost, he will traverse the streets in a way, that every subsequently passed street has been traversed at a later moment than the previous one (according to the memories of Bobby, the dog), or in other words, cnextc_{next} > ccurrentc_{current}. It is possible to pass a crossroad more than once.

Task

Kyushо wants his new walk to contain as many streets as possible and end at some crossroad, but he still hasn't decided where he will stop. So, he desires to know the longest walk to every crossroad following the rules of moving from the previous paragraph. Please, help him by writing a program, which finds the inquired maximal lengths with regards to the number of passed streets.

Input data

The first line of the standard input contains the two integers NN and MM – the count of the crossroads and the count of the streets between them. Each of the rest MM lines contains three integers – aia_i, bib_i and cic_i, which describe a street between the crossroads with numbers aia_i and bib_i, traversed at moment cic_i (according to the memories of Bobby, the dog).

Output data

The only line of the standard output should contain NN integers, each separated by a space – the maximal lengths of walks from crossroad 11 to all crossroads 1,2,,N1, 2, \dots, N. If there is no possible walk to one of them, you should print 00 as the maximal length of a walk to this crossroad.

Constraints and clarifications

  • 2N1052 \leq N \leq 10^5
  • 1M1061 \leq M \leq 10^6
  • 1ai,biN1 \leq a_i,b_i \leq N, aibia_i \neq b_i
  • 1ci1091 \leq c_i \leq 10^9
# Score Constraints
1 0 Example
2 10 N10N \leq 10, M15M \leq 15
3 7 M=N1M = N - 1
4 29 N103N \leq 10^3, M104M \leq 10^4
5 27 M3×105M \leq 3 \times 10^5 and cicjc_i \neq c_j for iji \neq j
6 7 M3×105M \leq 3 \times 10^5
7 14 cicjc_i \neq c_j for iji \neq j
8 6 No additional constraints

Example

stdin

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

stdout

3 3 6 7 8 2 7 4

Explanation

Illustration of the streets and crossroads:

Optimal walk to crossroad with number 33 is the following: 115266278851031 \overset{1}{-} 5 \overset{2}{-} 6 \overset{6}{-} 2 \overset{7}{-} 8 \overset{8}{-} 5 \overset{10}{-} 3.

Notice, that when we are at crossroad 88 in the walk, we cannot continue to crossroad 77 because the moment of that street is 55 but we have come from a street with moment 77.

Log in or sign up to be able to send submissions!