Problem D
Let's Play Monopoly!
Monopoly is a fast-dealing property trading game, which is firstly designed by Elizabeth Magie and then published as well as owned by Hasbro. Since its first appearance in 1935, this game has quickly become well-known and deserves the best way of enjoying with friends at leisure. In this game, you can demonstrate your powerful investing skill and your great support from the God by throwing dices, travelling on a risky board and building your real estate for the purpose of forcing your opponents to pay huge amounts of money for renting your land, which eventually leads to bankruptcy. Various localized versions of Monopoly have been introduced, consisting of different famous places all over the world, while their layout share the same. The figure below shows the board of UK Edition Monopoly.
![\includegraphics[width=0.5\textwidth ]{board.jpg}](/problems/monopoly/file/statement/en/img-0001.jpg)
If you have enjoyed delightful moments with Monopoly, I wish you can entertain yourselves by solving this problem. Otherwise, do not worry as in this problem we are playing a significantly simplified version of this game. Forget the rules of the traditional game and read carefully the below description:
In this problem, instead of a board, the game is held in a
graph with
Every node belongs to one of the following types:
-
Property: You can purchase to own this property and force your opponents to pay you when they reach here. Each property has its own buying cost and renting cost. Initially, all properties are unowned. When you reach an unowned property, you can decide either to buy this property (you have to pay its buying cost) to permanently own it, or to ignore. After you purchase for this property, your opponent has to send you an amount of money equal to its renting cost everytime he reaches it. Of course, you have nothing to do while landing on your own properties.
-
Salary: Each node of this kind has its own value, which is the amount of money you gain everytime you reach this.
-
Tax: Each node of this kind has its own value, which is the amount of money you lose when you reach this node.
Since Alob and Bice are bored of playing an overlong game,
each person will take at most
Assume that both player play optimally, your task is to determine the outcome of the game.
Input
The first line contains five integers:
The
The
-
PROPERTY b r: Denotes that this node has a property with buying_cost
and renting_cost . -
SALARY v: Denotes that a player earns
when entering this node. -
TAX v: Denotes that a player loses
when entering this node.
Output
Write out in one line two space-separated integers denoting the amount of money Alob and Bice gain at the end of the game, respectively.
Constraints
-
-
-
-
, -
All other numbers in the input files are integers between
and , inclusive. -
For all nodes which has property,
. -
For every
from to , .
Sample Input 1 | Sample Output 1 |
---|---|
12 12 123456789 1 2 1 3 1 5 3 7 3 9 5 9 7 11 2 4 2 6 4 8 4 10 6 8 8 12 SALARY 1 SALARY 10000 TAX 3 TAX 200 SALARY 10 TAX 1000 SALARY 7 PROPERTY 50 14 TAX 18 PROPERTY 105 33 PROPERTY 11 2 SALARY 7 |
4 -193 |