CF903G.Yet Another Maxflow Problem

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In this problem you will have to deal with a very special network.

The network consists of two parts: part AA and part BB . Each part consists of nn vertices; ii -th vertex of part AA is denoted as AiA_{i} , and ii -th vertex of part BB is denoted as BiB_{i} .

For each index ii ( 1<=i<n1<=i<n ) there is a directed edge from vertex AiA_{i} to vertex Ai+1A_{i+1} , and from BiB_{i} to Bi+1B_{i+1} , respectively. Capacities of these edges are given in the input. Also there might be several directed edges going from part AA to part BB (but never from BB to AA ).

You have to calculate the maximum flow value from A1A_{1} to BnB_{n} in this network. Capacities of edges connecting AiA_{i} to Ai+1A_{i+1} might sometimes change, and you also have to maintain the maximum flow value after these changes. Apart from that, the network is fixed (there are no changes in part BB , no changes of edges going from AA to BB , and no edge insertions or deletions).

Take a look at the example and the notes to understand the structure of the network better.

输入格式

The first line contains three integer numbers nn , mm and qq ( 2<=n,m<=21052<=n,m<=2·10^{5} , 0<=q<=21050<=q<=2·10^{5} ) — the number of vertices in each part, the number of edges going from AA to BB and the number of changes, respectively.

Then n1n-1 lines follow, ii -th line contains two integers xix_{i} and yiy_{i} denoting that the edge from AiA_{i} to Ai+1A_{i+1} has capacity xix_{i} and the edge from BiB_{i} to Bi+1B_{i+1} has capacity yiy_{i} ( 1<=xi,yi<=1091<=x_{i},y_{i}<=10^{9} ).

Then mm lines follow, describing the edges from AA to BB . Each line contains three integers xx , yy and zz denoting an edge from AxA_{x} to ByB_{y} with capacity zz ( 1<=x,y<=n1<=x,y<=n , 1<=z<=1091<=z<=10^{9} ). There might be multiple edges from AxA_{x} to ByB_{y} .

And then qq lines follow, describing a sequence of changes to the network. ii -th line contains two integers viv_{i} and wiw_{i} , denoting that the capacity of the edge from AviA_{vi} to Avi+1A_{vi}+1 is set to wiw_{i} ( 1<=vi<n1<=v_{i}<n , 1<=wi<=1091<=w_{i}<=10^{9} ).

输出格式

Firstly, print the maximum flow value in the original network. Then print qq integers, ii -th of them must be equal to the maximum flow value after ii -th change.

输入输出样例

  • 输入#1

    4 3 2
    1 2
    3 4
    5 6
    2 2 7
    1 4 8
    4 3 9
    1 100
    2 100
    

    输出#1

    9
    14
    14
    

说明/提示

This is the original network in the example:

首页