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

Source: Internet
Author: User
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 graphNVertices andMEdges. 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 integersN,M(2 cores ≤ CoresNLimit ≤ limit 3 · 105; 1 limit ≤ limitMLimit ≤ limitMin(N·(NInterval-interval 1), interval 3 · 105). Then,MLines follows.I-Th line contains three space separated integers:UI,VI,WI(1 digit ≤ DigitUI, Bytes,VILimit ≤ limitN; 1 bytes ≤ bytesWILimit ≤1_105) which indicates that there's a ccted edge with weightWIFrom VertexUITo VertexVI.

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

Output

Print a single integer-the answer to the problem.

 

Question: Find the longest path of the monotonically unchanged path weight for a given graph.

SL: sort the order directly, and then run DP. Each edge is equivalent to a restriction. But note that the records with the same length will not be updated, so it is better to open an array of records.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.