Problem Description: Maximize Score in a Directed Graph
In this task, you will work with a directed graph that consists of N vertices and M edges. Each directed edge has an associated weight, representing the score gained when traversing that edge.
Game Rules:
You start at vertex 1 with an initial score of 0.
You can move your piece along the directed edges from vertex a_i to vertex b_i and gain a score of c_i where (a_i, b_i, c_i) represents the i-th edge.
Your objective is to reach vertex N, at which point the game ends.
Your goal is to maximize your score throughout the journey to vertex N.
If it is possible to infinitely increase the score by traversing cycles within the graph, you should return "inf".
Input Format:
The first line contains two integers, N (the number of vertices) and M (the number of edges).
The next M lines each contain three integers: a_i, b_i, and c_i which represent a directed edge from vertex a_i to vertex b_i with weight c_i.
Output Format:
Output a single integer which is the maximum score achievable when reaching vertex N. If it's possible to increase the score indefinitely, print "inf".
Constraints:
1 ≤ N ≤ 1000
1 ≤ M ≤ 10000
1 ≤ a_i, b_i ≤ N
-10^6 ≤ c_i ≤ 10^6
Example Input:
text
4 5
1 2 5
1 3 10
2 4 10
3 4 5
3 2 1
Example Output:
text
15
Explanation:
In the example, the optimal path to maximize the score is from vertex 1 to vertex 3 (score +10), and then from vertex 3 to vertex 4 (score +5). The total score when reaching vertex 4 is 15.
Example Input:
text
3 3
1 2 10
2 3 5
2 1 -5
Example Output:
text
inf
Explanation:
In this case, you can continue to traverse between vertex 1 and 2, accumulating more and more points, leading to an infinite score.