WALK

시간 제한1.5초메모리 제한1024 MB

요약
1번 정점에서 출발해 지나온 간선의 기억 시각이 계속 커지는 조건에서 각 정점까지 지날 수 있는 간선 수의 최댓값을 구한다.
난이도

보통10점 중 6점

유형
그래프, 동적 계획법, 정렬
정답자
아직 제출이 없습니다

문제

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 a_ia\_i and b_ib\_i was traversed at moment c_ic\_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, c_nextc\_{next} > c_currentc\_{current}. It is possible to pass a crossroad more than once.

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 walk, which finds the inquired maximal lengths with regards to the number of passed streets.

입력

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 – a_ia\_i, b_ib\_i and c_ic\_i, which describe a street between the crossroads with numbers a_ia\_i and b_ib\_i, traversed at moment c_ic\_i (according to the memories of Bobby, the dog).

출력

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.

제한

  • 2≤N≤1052 \leq N \leq 10^5
  • 1≤M≤1061 \leq M \leq 10^6
  • 1≤a_i,b_i≤N1 \leq a\_i,b\_i \leq N, a_i≠b_ia\_i \neq b\_i
  • 1≤c_i≤1091 \leq c\_i \leq 10^9

힌트

Illustration of the streets and crossroads:

Optimal walk to crossroad with number 33 is the following: 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.\\ 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.}

예제1

  1. 예제 1

    입력
    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
    
    예상 출력
    3 3 6 7 8 2 7 4