#BF0000026. Trì hoãn đầy cảm hứng (Inspired Procrastination)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Trì hoãn đầy cảm hứng (Inspired Procrastination)
Inspired Procrastination
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Life is modeled as decision points numbered through . You start at point . Each of directed choices moves from to and adds signed procrastination factor . You may revisit points and may stop anywhere, at any time. Find the maximum possible accumulated procrastination, or print Unlimited! if it can be increased without bound.
Input
The first line contains . Each following line has , where and no ordered pair is repeated.
Output
Print Unlimited! if unbounded, otherwise the maximum accumulated factor (at least because stopping immediately is permitted).
Subtasks
-
Subtask 1 (20 points): ; ; ; no self-loops or repeated directed pairs.
-
Subtask 2 (30 points): ; ; ; no self-loops or repeated directed pairs.
-
Subtask 3 (50 points): ; ; ; no self-loops or repeated directed pairs.
Examples
Input
3 3
1 2 10
2 3 20
3 1 -30
Output
30
Explanation
The walk yields . The cycle returning to vertex has weight , so it cannot increase the optimum.