#BF0000020. 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
You are given a directed graph with vertices and edges. Moving along an edge adds its possibly negative score . Start at vertex with score zero and finish only at vertex , which is reachable. Edges may be reused. Find the maximum finishing score, or print inf if it is unbounded.
Input
The first line contains , then lines . Self-loops and repeated ordered edge pairs are absent.
Output
Print inf if unbounded; otherwise print the maximum score.
Subtasks
-
Subtask 1 (20 points): ; ; ; no self-loops or duplicate directed pairs; target reachable.
-
Subtask 2 (30 points): ; ; ; no self-loops or duplicate directed pairs; target reachable.
-
Subtask 3 (50 points): ; ; ; no self-loops or duplicate directed pairs; target reachable.
Examples
Input
3 3
1 2 4
2 3 3
1 3 5
Output
7
Explanation
The route gains , compared with for the direct edge.