#P1807. 最长路
最长路
Description
Let be a weighted directed acyclic graph with vertices, labeled from to . Design an algorithm to compute the longest path from to in .
Input Format
The first line contains two integers, the number of vertices and the number of edges .
Lines to each contain three integers (), indicating there is a directed edge from to with weight .
Output Format
Output a single integer on one line, representing the length of the longest path from to .
If cannot reach , output .
2 1
1 2 1
1
Hint
Constraints
- For of the testdata, , .
- For of the testdata, , .
- For of the testdata, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号