#BF0000023. Nỗi lo của Omin-sik (Omin-sik’s Worry)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Nỗi lo của Omin-sik (Omin-sik’s Worry)
Omin-sik's Worry
Source: BOJ
Version: Phuoc Hung OJ Extended
Problem Statement
A traveling salesman travels from city to city among cities numbered from . Each directed route costs a nonnegative amount . Every visit to city earns money, including the initial visit to the starting city. Cities and routes may be revisited. Find the maximum cash upon reaching city , which can be negative. Print gg if unreachable or Gee if unbounded above.
Input
The first line has . Then lines , followed by city earnings .
Output
Print gg if the destination is unreachable, Gee if profit is unbounded, or the finite maximum money.
Subtasks
-
Subtask 1 (20 points): ; ; ; ; directed edges may be repeated.
-
Subtask 2 (30 points): ; ; ; ; directed edges may be repeated.
-
Subtask 3 (50 points): ; ; ; ; directed edges may be repeated.
Examples
Input
5 0 4 7
0 1 13
1 2 17
2 4 20
0 3 22
1 3 4747
2 0 10
3 4 10
0 0 0 0 0
Output
-32
Explanation
No city pays any earnings. The cheapest route is , costing , so final cash is .