File size: 4,872 Bytes
07f695f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
<p>
You're given an undirected, connected graph with <strong>N</strong> nodes (numbered from 1 to <strong>N</strong>) and <strong>N</strong> edges.
The <strong>i</strong>th edge connects distinct nodes <strong>A<sub>i</sub></strong> and <strong>B<sub>i</sub></strong>,
and has a capacity of <strong>C<sub>i</sub></strong>. No two edges directly connect the same pair of nodes.
</p>
<p>
<strong>M</strong> operations will be performed on this graph, one after another. The nature of the <strong>i</strong>th operation is described by the value of <strong>O<sub>i</sub></strong>:
<p>
- If <strong>O<sub>i</sub></strong> = 1, then the <strong>i</strong>th operation is an update, in which the capacity of the
<strong>X<sub>i</sub></strong>th edge is changed to be <strong>Y<sub>i</sub></strong>.
</p>
<p>
- Otherwise, if <strong>O<sub>i</sub></strong> = 2, then the <strong>i</strong>th operation is a query, in which you must determine the maximinimax flow in the graph after
<strong>Z<sub>i</sub></strong> edge augmentations.
</p>
<p>
What do any of those terms mean? Let's define them:
</p>
<p>
- An edge augmentation is a temporary increase of a certain edge's capacity by 1 for the current query.
</p>
<p>
- The max flow from node <strong>u</strong> to a different node <strong>v</strong> is the usual definition of maximum flow in computer science (hopefully you're familiar with it!),
with node <strong>u</strong> being the source and node <strong>v</strong> being the sink. Each edge may transport flow in either direction, so it may be thought of as two directed edges
(one in each direction), both with the same capacity.
</p>
<p>
- The minimax flow in the graph is the smallest max flow value across all pairs of distinct nodes. In other words,
min{1 ≤ <strong>u</strong>, <strong>v</strong> ≤ <strong>N</strong>, <strong>u</strong> ≠ <strong>v</strong>} (F(<strong>u</strong>, <strong>v</strong>)),
where F(<strong>u</strong>, <strong>v</strong>) is the max flow from node <strong>u</strong> to node <strong>v</strong>.
</p>
<p>
- The maximinimax flow in the graph after <strong>x</strong> edge augmentations is the largest possible minimax flow which the graph can have after
<strong>x</strong> optimal edge augmentations are applied. Note that each edge can be augmented any non-negative number of times
(as long as the total number of augmentations in the graph is <strong>x</strong>), and that the chosen edge augmentations are temporary — they do not change the graph for future operations.
</p>
<p>
To reduce the size of the output, you should simply output one integer, the sum of the answers to all of the queries.
</p>
<h3>Input</h3>
<p>
Input begins with an integer <strong>T</strong>, the number of graphs.
For each graph, there is a first a line containing the space-separated integers <strong>N</strong> and <strong>M</strong>.
Then, <strong>N</strong> lines follow, the <strong>i</strong>th of which contains the space-separated integers
<strong>A<sub>i</sub></strong>, <strong>B<sub>i</sub></strong>, and <strong>C<sub>i</sub></strong>.
Then, <strong>M</strong> lines follow, the <strong>i</strong>th of which contains the space-separated integers
<strong>O<sub>i</sub></strong>, <strong>X<sub>i</sub></strong>, and <strong>Y<sub>i</sub></strong> (if <strong>O<sub>i</sub></strong> = 1) or
<strong>O<sub>i</sub></strong> and <strong>Z<sub>i</sub></strong> (if <strong>O<sub>i</sub></strong> = 2).
</p>
<h3>Output</h3>
<p>
For the <strong>i</strong>th graph, print a line containing "Case #<strong>i</strong>: " followed by the sum of the answers to all queries on that graph.
</p>
<h3>Constraints</h3>
<p>
1 ≤ <strong>T</strong> ≤ 85 <br />
3 ≤ <strong>N</strong> ≤ 500,000 <br />
1 ≤ <strong>M</strong> ≤ 500,000 <br />
1 ≤ <strong>A<sub>i</sub></strong>, <strong>B<sub>i</sub></strong>, <strong>X<sub>i</sub></strong> ≤ <strong>N</strong> <br />
1 ≤ <strong>C<sub>i</sub></strong>, <strong>Y<sub>i</sub></strong> ≤ 1,000,000 <br />
0 ≤ <strong>Z<sub>i</sub></strong> ≤ 1,000,000,000,000 <br />
1 ≤ <strong>O<sub>i</sub></strong> ≤ 2 <br />
</p>
<h3>Explanation of Sample</h3>
<p>
In the first graph, the max flow between any two nodes is 10, so the minimax flow is also 10. If we do no edge augmentations, then the maximinimax flow is still 10.
In the second graph, the maximinimax flow is initially 3, but is then increased to 5 before the second query for a total of 8.
In the third graph, the maximinimax flow is initially 7 (between node 2 and any other node). If we augment the edge from node 3 to node 2 twice,
then the max flow between node 2 and any other node is now 9. The max flow between any other pair of nodes was already greater than 9, so the minimax flow is now 9.
We can't do any better than that, so the maximinimax flow is also 9.
</p>
|