#643
Unrated
Minimum Longest Trip
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Bessie is going on a trip in Cowland, which has NN (2N21052\le N\le 2\cdot 10^5) towns numbered from 11 to NN and MM (1M41051\le M\le 4\cdot 10^5) one-way roads. The iith road runs from town aia_i to town bib_i and has label lil_i (1ai,biN1\le a_i,b_i\le N, 1li1091\le l_i\le 10^9).

A trip of length kk starting at town x0x_0 is a sequence of towns x0,x1,,xkx_0, x_1, \ldots, x_k, such that there is a road from town xix_i to town xi+1x_{i+1} for all 0i<k0\le i < k. It is guaranteed that there are no trips of infinite length in Cowland, and that no two roads connect the same pair of towns.

For each town, Bessie wants to know the longest possible trip starting at it. For some starting towns, there are multiple longest trips - out of these, she prefers the trip with the lexicographically minimum sequence of road labels. A sequence is lexicographically smaller than another sequence of the same length if, at the first position in which they differ, the first sequence has a smaller element than the second sequence.

Output the length and sum of road labels of Bessie's preferred trip starting at each town.

입력

The first line contains NN and MM.

The next MM lines each contain three integers aia_i, bib_i, and lil_i, denoting a road from aia_i to bib_i with label lil_i.

출력

Output NN lines. The iith should contain two space-separated integers, the length and sum of road labels of Bessie's preferred trip starting at town ii.

예제 입력 1

4 5
4 3 10
4 2 10
3 1 10
2 1 10
4 1 10

예제 출력 1

0 0
1 10
1 10
2 20

예제 입력 2

4 5
4 3 4
4 2 2
3 1 5
2 1 10
4 1 1

예제 출력 2

0 0
1 10
1 5
2 12

예제 입력 3

4 5
4 3 2
4 2 2
3 1 5
2 1 10
4 1 1

예제 출력 3

0 0
1 10
1 5
2 7

예제 입력 4

4 5
4 3 2
4 2 2
3 1 10
2 1 5
4 1 1

예제 출력 4

0 0
1 5
1 10
2 7

점수

Inputs 5-6: All labels are the same.Inputs 7-8: All labels are distinct.Inputs 9-10: N,M5000N,M\le 5000Inputs 11-20: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.