The electrical grids of the United States and Italy have recently shown deficiencies. To prevent them, Catalan engineers are faced with the following problem.
Electricity must be sent, through several wires, from a power plant where it is produced to a city where it is consumed. Each wire is defined by some capacity and by two vertices that join them to other wires: an input vertex where electricity enters the wire and an output vertex where electricity leaves the wire. Every vertex can distribute electricity as it likes, as long as capacity restrictions are not violated and the amount of electricity that enters the vertex equals the amount of electricity that leaves it.
Which is the greatest amount of electricity shippable from the power plant to the city?
Input consists of several cases. Each case begins with the number of vertices and the number of wires . Follow trios of natural numbers , and , to indicate a wire from vertex to vertex (where ) with capacity . Vertices are labeled from 0 to . Vertex 0 corresponds to the power plant and vertex to the city. Assume and that for every two vertices and there is at most one wire from to .
For every case, print the maximum amount of electricity that can be sent from the power plant to the city.
Input
6 10 0 1 16 0 2 13 1 2 10 2 1 4 1 3 12 2 4 14 3 2 9 4 3 7 3 5 20 4 5 4 2 0 4 6 0 1 40 1 0 10 0 2 50 1 2 20 2 1 30 1 3 1000 8 9 0 1 3 0 2 2 1 4 3 2 3 2 3 4 2 1 5 2 5 6 2 6 7 2 4 7 3
Output
23 0 70 5