码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #261 (Div. 2) E (DP)

时间:2014-08-16 12:27:20      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:style   color   os   io   for   ar   div   line   

E. Pashmak and Graph

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 nm (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: uiviwi (1 ≤ ui, vi ≤ n; 1 ≤ wi ≤ 105) which indicates that there‘s a directed edge with weight wi from vertex ui to vertex vi.

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

Output

Print a single integer — the answer to the problem.

 

题意:求出给定图的单调不下降路径权值的最长路。

sl :直接排个序,然后dp搞一下,每条边相当于一个限制条件。但是注意的是,相同长度的不会被其更新,因此多开一数组记录就好了 

Codeforces Round #261 (Div. 2) E (DP),布布扣,bubuko.com

Codeforces Round #261 (Div. 2) E (DP)

标签:style   color   os   io   for   ar   div   line   

原文地址:http://www.cnblogs.com/acvc/p/3916201.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!