Water Supply Upgrades
Time limit2sMemory limit512 MB
After each of k permanent capacity increases on edges of a small graph, report the maximum flow between station 1 and station 2.
- Level
Medium7 of 10
- Topics
- Graph, Dynamic programming, Implementation, Brute force
- Solved
- No attempts yet
Problem
A water company sends water from its pumping station to a mansion. The company runs water stations, numbered 1 to , joined by pipes. Water flows through a pipe in either direction, and the total amount of water that passes through a pipe never exceeds the capacity of that pipe.
The company keeps improving its pipes. It carries out improvements, and an improvement is permanent once it is done. One improvement raises the capacity of the pipe between two stations by a fixed amount. If those two stations have no pipe between them yet, the improvement installs one with that capacity.
After each improvement the company wants to know the largest amount of water the mansion can receive.
Input
The input contains a single test case. The first line has three integers (), () and (), where is the number of stations, is the number of pipes already in place, and is the number of improvements. Station 1 is the pumping station and station 2 is the mansion.
Each of the next lines describes one pipe of the initial setup with three integers , () and (), meaning stations and are joined by a pipe of capacity . No pair appears more than once in this part of the input.
Each of the next lines describes one improvement with three integers , () and (), meaning the capacity of the pipe between stations and grows by . If there is no pipe between and at that moment, one of capacity is installed. A pair may repeat in this part of the input.
Output
Print integers, one per line. The first is the largest amount of water that reaches the mansion in the initial setup. The next numbers are that amount after each improvement, in the order the improvements are given.