Longest Path in a DAG
Print the maximum total edge weight of any directed path in a weighted DAG.
Input: the first line has N and M; each of the next M lines has u v w (the graph is acyclic).
Output: the longest path weight (0 if no edges).
Constraints:
- 2 ≤ N ≤ 105
- 1 ≤ M ≤ 2×105
- 1 ≤ w ≤ 1000
Sample Tests
Input 1
4 4 1 2 3 2 3 4 1 3 2 3 4 1
Output 1
8
Input 2
2 1 1 2 5
Output 2
5
Discussion (opens after you solve — no spoilers before)
No comments yet.