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搞一下,每条边相当于一个限制条件。但是注意的是,相同长度的不会被其更新,因此多开一数组记录就好了

最新文章

  1. 转一篇老外写的博文:Android automated testing (Robotium)
  2. Stream 流操作
  3. 改变服务器sshd 的22的端口
  4. 浅谈Java回调机制
  5. delphi快捷键
  6. assembly的说明
  7. JavaScript_object基础
  8. 跨控制器操作-thinkphp
  9. 【转载】ASP.NET页面运行机制以及请求处理流程
  10. 【Java】基本数据类型长度
  11. C# winfrom 模拟ftp文件管理
  12. php三元运算
  13. 面试 -- ListView对其指定的子Item进行单独的刷新
  14. POJ 1556 The Doors(线段相交+最短路)
  15. POJ 1426 - Find The Multiple - [DP][BFS]
  16. codeoforces 932A
  17. Delphi 10.3实现Android App的动态权限申请
  18. 17. Letter Combinations of a Phone Number (backtracking)
  19. (Delphi) Using the Disk Cache 使用磁盘缓存
  20. asp.net mvc 5 在没有外网win2008R2服务器部署方法

热门文章

  1. iOS9导入高德地图报错App Transport Security has blocked...
  2. jmeter(十四)解读聚合报告
  3. Object流
  4. 微信“摇一摇·周边”正式开放
  5. Java集合框架源码(三)——arrayList
  6. Sql Server 2012 事务复制遇到的问题及解决方式
  7. redis-cli 工具--raw参数的作用
  8. Windows之shortcut
  9. .Net Core 真能令微软的.Net 跨平台“蔓延”?
  10. tomcat添加访问的ip限制