Description
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.
Solution
题意:给出一个无自环、重边的带权有向图,求边权严格递增的最长的路径(可以是非简单路径)
思路题QAQ
O(mlogm)以边权排序后再逐个处理,这样就保证了递增,然后可以O(m)求解,维护每个点作为结尾的最长的边权上升路径的长度
注意边权相等的情况要放在一起处理
#include#include #include #include #include #define MAXN 300010using namespace std;int n,m,f[MAXN],g[MAXN];struct Node{ int u,v,w; bool operator < (const Node& x) const { return w