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)的更多相关文章

  1. Codeforces Round #261 (Div. 2)[ABCDE]

    Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...

  2. Codeforces Round #261 (Div. 2) E. Pashmak and Graph DP

    http://codeforces.com/contest/459/problem/E 不明确的是我的代码为啥AC不了,我的是记录we[i]以i为结尾的点的最大权值得边,然后wa在第35  36组数据 ...

  3. Codeforces Round 261 Div.2 E Pashmak and Graph --DAG上的DP

    题意:n个点,m条边,每条边有一个权值,找一条边数最多的边权严格递增的路径,输出路径长度. 解法:先将边权从小到大排序,然后从大到小遍历,dp[u]表示从u出发能够构成的严格递增路径的最大长度. dp ...

  4. 严格递增类的dp Codeforces Round #371 (Div. 1) C dp

    http://codeforces.com/contest/713 题目大意:给你一个长度为n的数组,每次有+1和-1操作,在该操作下把该数组变成严格递增所需要的最小修改值是多少 思路:遇到这类题型, ...

  5. 很好的一个dp题目 Codeforces Round #326 (Div. 2) D dp

    http://codeforces.com/contest/588/problem/D 感觉吧,这道题让我做,我应该是不会做的... 题目大意:给出n,L,K.表示数组的长度为n,数组b的长度为L,定 ...

  6. Codeforces Round #548 (Div. 2) C dp or 排列组合

    https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个 ...

  7. Codeforces Round #536 (Div. 2) E dp + set

    https://codeforces.com/contest/1106/problem/E 题意 一共有k个红包,每个红包在\([s_i,t_i]\)时间可以领取,假如领取了第i个红包,那么在\(d_ ...

  8. Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)

    https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...

  9. Codeforces Round #543 (Div. 2) F dp + 二分 + 字符串哈希

    https://codeforces.com/contest/1121/problem/F 题意 给你一个有n(<=5000)个字符的串,有两种压缩字符的方法: 1. 压缩单一字符,代价为a 2 ...

随机推荐

  1. Apusic中间件结合MyEclipse进行远程调试记录

    Apusic中间件结合MyEclipse进行远程调试记录. 在金蝶域中正常部署应用. 启动金蝶中间件时使用"startapusic -ds"命令. 在MyEclipse的Run-- ...

  2. domain admin域管理员

    当计算机加入到域后,默认将"Domain Admins"组赋予了本地系统管理员的权限.也就是说,在计算机添加到域,成为域的成员主机的过程中,系统将会自动把"Domain ...

  3. [完美方案+无懈可击]ubuntu 14.04(LTS) + GTX 980Ti显卡配置

    安装好系统之后出现的问题: 1 不能上网:后来通过删除链接新建一个以太网链接(自动DHCP)重启莫名其妙就好使了. 2 分辨率只有两个:1024x ? 和 800x600. 分辨率低到让人头痛.通过查 ...

  4. .net 发送邮件验证码

    using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Net.Ma ...

  5. ajax通过新闻id获取列表

    <div class="index_main">        <div class="page_l">           <i ...

  6. 防止系统页面被加载进 iframe 子窗口

    在controller的返回的响应头中添加 response.addHeader("x-frame-options", "DENY");  即可

  7. hihocoder 分隔相同字符

    思路: 枚举,贪心. 在“合法”的前提下放置越排在前边的字母越好. “合法”:'a' - 'z'中没有一个字母的个数超过当前串剩余长度的一半(偶数情况下)或长度的一半加1(奇数情况下). 实现: #i ...

  8. [BZOJ1046][HAOI2007]上升序列 DP+贪心

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1046 我们先求出对于每一个数字作为开头的LCS的长度f[i],最长的f[i]为mxlen. ...

  9. 一种结合hudson的算法自动化测试构想

    作者:朱金灿 来源:http://blog.csdn.net/clever101 有时我在思考:未来软件测试的趋势是什么?其实答案和其它行业一样简单:低技术含量的测试工作都将由机器承担,人只能干机器干 ...

  10. 用idea+maven编译打包spark project core错误:java.lang.RuntimeException: Unable to load a Suite class

    Discovery starting. *** RUN ABORTED *** java.lang.RuntimeException: Unable to load a Suite class tha ...