Skip to content

Commit 051601d

Browse files
committed
Use Copy from mutable
1 parent 1388009 commit 051601d

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

maxflow.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,8 @@ package graph
77
func MaxFlow(g Iterator, s, t int) (flow int64, graph Iterator) {
88
// Edmonds-Karp's algorithm
99
n := g.Order()
10-
residual := New(n)
11-
for v := 0; v < n; v++ {
12-
g.Visit(v, func(w int, c int64) (skip bool) {
13-
residual.AddCost(v, w, c)
14-
return
15-
})
16-
}
1710
prev := make([]int, n)
11+
residual := Copy(g)
1812
for residualFlow(residual, s, t, prev) && flow < Max {
1913
pathFlow := Max
2014
for v := t; v != s; {
@@ -41,11 +35,10 @@ func MaxFlow(g Iterator, s, t int) (flow int64, graph Iterator) {
4135
return
4236
})
4337
}
44-
graph = Sort(res)
45-
return
38+
return flow, Sort(res)
4639
}
4740

48-
func residualFlow(g Iterator, s, t int, prev []int) bool {
41+
func residualFlow(g *Mutable, s, t int, prev []int) bool {
4942
visited := make([]bool, g.Order())
5043
prev[s], visited[s] = -1, true
5144
for queue := []int{s}; len(queue) > 0; {

0 commit comments

Comments
 (0)