Codeforces Round 261 (Div. 2)
E
Pashmak and Graph
Codeforces
1900
原题
← D→
翻译中…

Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he can't solve this problem. As you know, he's really weak at graph theory; so try to help him in solving the problem.

翻译中…

You are given a weighted directed graph with $*n*$ vertices and $*m*$ edges. You need to find a path (perhaps, non-simple) with maximum number of edges, such that the weights of the edges increase along the path. In other words, each edge of the path must have strictly greater weight than the previous edge in the path.

翻译中…

Help Pashmak, print the number of edges in the required path.

翻译中…

Input

翻译中…

The first line contains two integers $*n*$, $*m*$ $(2 ≤ *n* ≤ 3·10^{5}; 1 ≤ *m* ≤ *min*(*n*·(*n* - 1), 3·10^{5}))$. Then, $*m*$ lines follows. The $*i*$-th line contains three space separated integers: $*u*_{*i*}$, $*v*_{*i*}$, $*w*_{*i*}$ $(1 ≤ *u*_{*i*}, *v*_{*i*} ≤ *n*; 1 ≤ *w*_{*i*} ≤ 10^{5})$ which indicates that there's a directed edge with weight $*w*_{*i*}$ from vertex $*u*_{*i*}$ to vertex $*v*_{*i*}$.

翻译中…

It's guaranteed that the graph doesn't contain self-loops and multiple edges.

翻译中…

Output

翻译中…

Print a single integer — the answer to the problem.

翻译中…

Note

翻译中…

In the first sample the maximum trail can be any of this trails: image.

翻译中…

In the second sample the maximum trail is image.

翻译中…

In the third sample the maximum trail is image.

翻译中…

样例

Input #1
3 3
1 2 1
2 3 1
3 1 1
Output #1
1
InputCopy OutputCopy
Input #2
3 3
1 2 1
2 3 2
3 1 3
Output #2
3
InputCopy OutputCopy
Input #3
6 7
1 2 1
3 2 5
2 4 2
2 5 2
2 6 9
5 4 3
4 3 4
Output #3
6
InputCopy OutputCopy
题目信息
题号
459E
时间限制
1 s
内存限制
256 MB
标签
动态规划
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。