Description
Every timeit rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means thatthe clover is covered by water for awhile and takes quite a long timeto regrow. Thus, Farmer John has built a setof drainage ditches so that Bessie's clover patch is never covered in water. Instead, the water is drained to a nearby stream. Being an ace engineer, Farmer John has also installed regulators atthebeginningof each ditch, so he can control at what rate water flows intothat ditch.
Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout ofthe ditches, which feed out ofthe pond andinto each other and stream in a potentially complex network.
Given all this information, determine the maximum rate at which water can be transported out ofthe pond andintothe stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle.
Input
The input includes several cases. For each case, thefirst line contains two space-separated integers, N (0 <= N <= 200) and M (2 <= M <= 200). N isthenumberof ditches that Farmer John has dug. M isthenumberof intersections points for those ditches. Intersection 1isthe pond. Intersection point M isthe stream. Each ofthe following N lines contains three integers, Si, Ei, and Ci. Si and Ei (1 <= Si, Ei <= M) designate the intersections between which this ditch flows. Water will flow through this ditch from Si to Ei. Ci (0 <= Ci <= 10,000,000) isthe maximum rate at which water will flow throughthe ditch.
Output
For each case, output a single integer, the maximum rate at which water may emptied fromthe pond.
Sample Input
5412401420242023303410
Sample Output
50
DescriptionEvery time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow