Pathwalks

题意翻译

### 题目描述 给定 $n$ 个点 $m$ 条边的有向图,可能不连通,可能有重边,也可能会有自环。求最长的路径(可以经过重复节点),使得这条路径的编号和权值都**严格**单调递增,其中编号指输入的顺序。路径的长度是指经过边的数量。 ### 输入格式 第一行两个整数 $n,m$。 第二行到第 $m+1$ 行,每行三个整数 $a,b,k$,表示顶点 $a$ 与顶点 $b$ 有一条边相连,边权为 $k$。 ### 输出格式 一行一个整数,表示最长的路径的长度。 $1\leq n,m\leq10^5$,$0\le w_i\le10^5$。 retranslated by @皎月半洒花。

题目描述

You are given a directed graph with $ n $ nodes and $ m $ edges, with all edges having a certain weight. There might be multiple edges and self loops, and the graph can also be disconnected. You need to choose a path (possibly passing through same vertices multiple times) in the graph such that the weights of the edges are in strictly increasing order, and these edges come in the order of input. Among all such paths, you need to find the the path that has the maximum possible number of edges, and report this value. Please note that the edges picked don't have to be consecutive in the input.

输入输出格式

输入格式


The first line contains two integers $ n $ and $ m $ ( $ 1<=n<=100000 $ , $ 1<=m<=100000 $ ) — the number of vertices and edges in the graph, respectively. $ m $ lines follows. The $ i $ -th of these lines contains three space separated integers $ a_{i} $ , $ b_{i} $ and $ w_{i} $ ( $ 1<=a_{i},b_{i}<=n $ , $ 0<=w_{i}<=100000 $ ), denoting an edge from vertex $ a_{i} $ to vertex $ b_{i} $ having weight $ w_{i} $

输出格式


Print one integer in a single line — the maximum number of edges in the path.

输入输出样例

输入样例 #1

3 3
3 1 3
1 2 1
2 3 2

输出样例 #1

2

输入样例 #2

5 5
1 3 2
3 2 3
3 4 5
5 4 0
4 5 8

输出样例 #2

3

说明

The answer for the first sample input is $ 2 $ : ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF960F/64f1808592d29bd3c0ddf93b30b30da2e43f461a.png). Note that you cannot traverse ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF960F/701350564a202a853dc0a2e9276e318c9ca164a2.png) because edge ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF960F/b59064b21bfeab8af7de18849682bc80881d0361.png) appears earlier in the input than the other two edges and hence cannot be picked/traversed after either of the other two edges. In the second sample, it's optimal to pick $ 1 $ -st, $ 3 $ -rd and $ 5 $ -th edges to get the optimal answer: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF960F/da8446025ba10d3435163cc331ea49b0612f49e8.png).