In his last escapade, Digger successfully picked up the underground treasure and continued to dig down with his souped-up pneumatic drill, hoping to come up in China. To his surprise, however, he instead stumbled upon the planet core. He quickly cooks up a new plan - to rocket up to the surface via a volcano.
He observes
The lake that Digger counts as Lake
All rivers and lakes are originally empty, but when an eruption occurs, lava starts to gush out of the core and along the rivers so that the rate of lava flowing into the volcanic lake is maximized. Digger plans to hop into the volcanic lake (using the inflatable heat-proof raft he keeps in his pocket) and wait for an eruption to occur, but he wants to know in advance the rate of lava that will be flowing into the lake.
Input Specification
Line |
|
Lines |
|
Lines |
Output Specification
Output the maximum rate at which lava can flow into the volcanic lake (in gallons per second).
Sample Input
6 8
10
3
4
6
2
0
1 2
1 3
2 3
2 4
3 4
3 5
4 6
5 6
Sample Output
7
Explanation
Below is a graphical representation of the river system (the boxed-in
numbers are lakes, the adjacent numbers are their flow rates, the
The amount of lava that flows through each river (this is just one possible solution) is shown below:
Comments