#P6005. [USACO20JAN] Time is Mooney G
[USACO20JAN] Time is Mooney G
Problem Description
Bessie is planning a business trip to Cow-nia, which has cities () numbered , connected by () one-way roads. Each time Bessie visits city , she can earn Mooney (). Starting from city , Bessie wants to earn as much Mooney as possible and finally return to city . To avoid disputes, .
Traveling along a road between two cities takes one day. Preparing for the trip is very expensive; traveling for days costs Mooney ().
What is the maximum amount of Mooney Bessie can earn in one trip? Note that the best plan might be that Bessie does not visit any city other than city ; in this case, the answer should be .
Input Format
The first line contains three integers , , and .
The second line contains integers .
Each of the next lines contains two space-separated integers and (), indicating a one-way road from city to city .
Output Format
Output one line containing the required answer.
3 3 1
0 10 20
1 2
2 3
3 1
24
Hint
The best travel plan is . Bessie earns a total of Mooney.
Translated by ChatGPT 5