9/23/2015acm-icpc1 maximum flow problem source t fg e 42 target (sink) 1 322 32 flow capacity b s c...
TRANSCRIPT
04/21/23 ACM-ICPC 1
Maximum Flow Problem
Source
t
f g
e
4 2
Target(sink)
1
3 2 2
32
flowcapacity
b
s
c
a
d e
2/3/
actual flow
1/2/
1/
1/
2/
2/
1. Actual flow capacity2. The source node can
produce flow as much as possible
3. For every node other than s and t, flow out flow in
The target node’s flow-in is called the flow of the graph
A node may have different ways to dispatch its flow-out .
What is the maximum flow of the graph?
04/21/23 ACM-ICPC 2
What makes the maximum flow problem more difficult than the shortest path problem?
Source
t
f g
e
4 2
Target
1
3 2 2
32
b
s
c
a
d e
2/3/
1/2/
1/
1/
2/
2/
The shortest path of t is based on the shortest path of g.
once a node’s shortest path from s is determined, we will never have to revise the decision
The maximum flow to t is not based on the maximum flows to f and g.
04/21/23 ACM-ICPC 3
local optimum does not imply global optimum
Source
Target
s
a b
c d
tTarget
4/5 2/2
3/3
0/1
2/31/4
3/3
Target
Source
s
a b
c d
5/5 2/2
0/3
1/1
3/34/4
0/3
scmax flow = 6
sdmax flow = 7
Source
s
a b
c d
5/5 2/2
1/3
1/1
3/33/4
1/3
2/2 5/5
stmax flow = 7
04/21/23 ACM-ICPC 4
A naïve approach: adding all possible paths together
tTarget
Source
b
d
3 2
3
1
24
2 3
2/
2/
2/
s
a
c
tTarget
Source
1 2
1
1
24
3
a
c
2/
2/
2/
b
d
s
Residual Graph
tTarget
Source
1
1
1
4
1
c
b
Residual Graph
1/
1/
1/
a
d
s
04/21/23 ACM-ICPC 5
Not always work. t
Target
Source
1
1
3
a
c
b
d
s
Residual Graph
tTarget
Source
b
d
2/2
3
1
2/2
2 3/3
3/3
2/
s
c
a
1/4
We are just lucky
04/21/23 ACM-ICPC 6
We may have a wrong choice:
tTarget
Source
b
32
3
1
24
2 3
3/s
c
3/
3/
tTarget
Source
b
d
2
3
1
21
2
s
a
cd
a
So, we keep a path for changing decision:
04/21/23 ACM-ICPC 7
Keep a path for changing decision:
tTarget
Source
b
32
3
1
24
2 3
3/s
c
3/
3/
Target
Source
b
2
3
1
21
2
s
cd
a
3
d
t
3
3
Augmented Graph
a
04/21/23 ACM-ICPC 8
Find another path in the augmented graph
Target
Source
2
3
1
21
2
3
3
3
Augmented Graph
2/
2/
2/
2/
2/
b
s
c
a
t
d
new Augmented Graph
2
1
1
21
2
3
1
3
2
2b
s
t
c
a
d
2
1
1
23
2
3
1
3
2
b
s
t
c
a
d
No more path from s to t
04/21/23 ACM-ICPC 9
Add flows together
Target
Maximum Flow
2
2
2
2
2
b
s
c
a
t
d
+
tTarget
Source
b
3s
c
3
3
d
a
=
Target
2
2
2
2
b
c
t
3
d
s3
a
1
04/21/23 ACM-ICPC 10
An algorithm for finding the maximum flow of graphs
Input: G = (V, E), and s,t V
Let Gmax = (, ), Gaug = G
1. Find a path p from s to t in Gaug
2. If no such p exists, output Gmax and stop the program
3. Add p into Gmax and update Gaug
4. Repeat 1, 2, and, if possible, 3
Complexity: O(f |E|)
04/21/23 ACM-ICPC 11
Claim: This algorithm always terminates with a maximum flow of the input graph
Input: G = (V, E), and s,t V
Let Gmax = (, ), Gaug = G
1. Find a path p from s to t in Gaug
2. If no such p exists, output Gmax and stop the program3. Add p into Gmax and update Gaug
4. Repeat 1, 2, and 3 if possible
The proof is somewhat difficult and beyond the scope of 279.
I say: No, it is not difficult and every one here should know.
• Since any given graph has a finite maximum flow, and every path from s to t, if any, provides a positive flow, the program therefore cannot run forever.
• By contradiction, suppose the algorithm terminates with a flow in Gmax. that is not maximum.
Then, there must be a flow not included in Gmax. But, if this is the case, there must be a path from s to t to carries this flow, and hence the program should not terminate at this moment. A contradiction.
04/21/23 ACM-ICPC 12
An inefficient situation
Target
Source
1000
1
1000
1000 1000
1
1/
1/
1/
1/ 1/
1/
1/a
s
t
b
04/21/23 ACM-ICPC 13
An inefficient situation
Target
Source
1000
1
1000
1000 1000
1/
1/
1/ 1/
1/
a
s
t
b
2/
2/
2/
2/
04/21/23 ACM-ICPC 14
Solution
Target
Source
1000 1000
1000 10001/
s
b
1000/
1000/
t
a
Always chose the maximum next edge