PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BF0000019. Điểm số cao nhất (High Score)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Điểm số cao nhất (High Score)
High Score
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
A game has rooms and one-way tunnels. Begin at room with score . Each traverse of a tunnel from to changes the score by signed integer . Tunnels can be reused. Find the maximum score attainable on reaching room , guaranteed reachable. Print -1 if the score is unbounded above.
Input
The first line has ; each of the next lines contains for a one-way tunnel.
Output
Print -1 if the score is unbounded; otherwise the maximum score.
Subtasks
-
Subtask 1 (20 points): ; ; ; target reachable from .
-
Subtask 2 (30 points): ; ; ; target reachable from .
-
Subtask 3 (50 points): ; ; ; target reachable from .
Examples
Input
4 5
1 2 3
2 4 -1
1 3 -2
3 4 7
1 4 4
Output
5
Explanation
The route scores , the maximum.