#FW0000124. Tấn công điểm số (Score Attack)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tấn công điểm số (Score Attack)
Score Attack
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given a directed graph with integer edge scores, possibly negative, start at vertex with score zero. Each edge traversal adds its weight to the score. You may end only at vertex , which is guaranteed reachable from . Find the maximum final score, or print exactly inf if a reachable positive cycle can be used indefinitely and still allows reaching .
Input
First line ; then directed edges . Vertices are -indexed; no self-loops or duplicated ordered edge pairs.
Output
Print the maximum score or inf.
Subtasks
-
Subtask 1 (40 points): , , , tồn tại đường từ tới . All input conditions remain in force.
-
Subtask 2 (60 points): , , , tồn tại đường từ tới . All input conditions remain in force.
Examples
Input
3 3
1 2 4
2 3 3
1 3 5
Output
7
Explanation
The route 1->2->3 scores 4+3=7, more than the direct edge scoring 5.