CF459E.Pashmak and Graph
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
帕什马克的作业是一道关于图论的题目。尽管他总是尽力完成全部作业,但他却无法解决这道题。众所周知,他在图论方面非常薄弱;因此,请你帮助他解决这个问题。
给定一个包含 n 个顶点和 m 条边的带权有向图。你需要找出一条(可能非简单)路径,使得该路径所含边数最多,且路径上各边的权重严格递增。换言之,路径中每条边的权重必须严格大于其前一条边的权重。
请帮助帕什马克,输出所求路径中边的数量。
输入格式
The first line contains two integers n, m (2 ≤ n ≤ 3·105; 1 ≤ m ≤ min(n·(n - 1), 3·105)). 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 ≤ 105) 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.
第一行包含两个整数 n、m(2≤n≤3⋅105;1≤m≤min(n⋅(n−1),3⋅105))。随后是 m 行。第 i 行包含三个以空格分隔的整数:ui、vi、wi(1≤ui,vi≤n;1≤wi≤105),表示存在一条从顶点 ui 指向顶点 vi 的有向边,其权值为 wi。
保证图中不含自环和重边。
输出格式
Print a single integer — the answer to the problem.
输出一个整数——该问题的答案。
输入输出样例
输入#1
3 3 1 2 1 2 3 1 3 1 1
输出#1
1
输入#2
3 3 1 2 1 2 3 2 3 1 3
输出#2
3
输入#3
6 7 1 2 1 3 2 5 2 4 2 2 5 2 2 6 9 5 4 3 4 3 4
输出#3
6
说明/提示
In the first sample the maximum trail can be any of this trails:
.
In the second sample the maximum trail is
.
In the third sample the maximum trail is
.
在第一个样例中,最长路径可以是以下任意一条路径:
。
在第二个样例中,最长路径是:
。
在第三个样例中,最长路径是:
。
输入解题思路,AI测评打分。不知道怎么写?