#BF0000021. Đồng xu hồi sinh (Coins Respawn)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đồng xu hồi sinh (Coins Respawn)
Coins Respawn
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You start at vertex with zero coins in a directed graph. Every traversal of edge takes one minute and awards coins, replenished on every visit. At vertex you may stop by pressing a button, or continue. On stopping after minutes, pay coins (or all your coins if insufficient). The remaining number of coins is your score. Find the maximum possible score, or print -1 if unbounded. Vertex is reachable.
Input
First line contains , followed by lines .
Output
Print -1 if unbounded; otherwise print the maximum nonnegative remaining coins.
Subtasks
-
Subtask 1 (20 points): ; ; ; ; ; vertex reachable from ; parallel edges allowed.
-
Subtask 2 (30 points): ; ; ; ; ; vertex reachable from ; parallel edges allowed.
-
Subtask 3 (50 points): ; ; ; ; ; vertex reachable from ; parallel edges allowed.
Examples
Input
3 3 10
1 2 20
2 3 30
1 3 45
Output
35
Explanation
The two-edge route yields ; the direct route yields , which is optimal.