Under construction

Still being built. Things may change

Water Supply Upgrades

Time limit2sMemory limit512 MB

Summary
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 nn water stations, numbered 1 to nn, 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 kk 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 nn (2≤n≤1002 \le n \le 100), pp (0≤p≤n(n−1)/20 \le p \le n(n-1)/2) and kk (1≤k≤100001 \le k \le 10000), where nn is the number of stations, pp is the number of pipes already in place, and kk is the number of improvements. Station 1 is the pumping station and station 2 is the mansion.

Each of the next pp lines describes one pipe of the initial setup with three integers aa, bb (1≤a<b≤n1 \le a < b \le n) and cc (1≤c≤10001 \le c \le 1000), meaning stations aa and bb are joined by a pipe of capacity cc. No pair (a,b)(a, b) appears more than once in this part of the input.

Each of the next kk lines describes one improvement with three integers aa, bb (1≤a<b≤n1 \le a < b \le n) and cc (1≤c≤10001 \le c \le 1000), meaning the capacity of the pipe between stations aa and bb grows by cc. If there is no pipe between aa and bb at that moment, one of capacity cc is installed. A pair (a,b)(a, b) may repeat in this part of the input.

Output

Print k+1k+1 integers, one per line. The first is the largest amount of water that reaches the mansion in the initial setup. The next kk numbers are that amount after each improvement, in the order the improvements are given.

Examples2

  1. Example 1

    Input
    3 2 1
    1 3 10
    2 3 1
    2 3 15
    
    Expected output
    1
    10
    
  2. Example 2

    Input
    6 10 2
    1 3 2
    1 4 6
    1 5 1
    3 5 8
    4 5 7
    2 4 3
    2 5 4
    2 6 1
    5 6 9
    3 6 5
    2 6 9
    1 6 3
    
    Expected output
    8
    9
    12