@@ -1408,7 +1408,7 @@ def _find_path_dfs(graph, s, t, flow_pass):
1408
1408
stack = Stack ()
1409
1409
parent = {}
1410
1410
1411
- stack .appendd (s )
1411
+ stack .append (s )
1412
1412
visited [s ] = True
1413
1413
1414
1414
while stack :
@@ -1417,19 +1417,19 @@ def _find_path_dfs(graph, s, t, flow_pass):
1417
1417
if curr == t :
1418
1418
break
1419
1419
1420
- for i in graph .i (curr ):
1420
+ for i in graph .neighbors (curr ):
1421
1421
i_name = i .name
1422
1422
capacity = graph .get_edge (curr , i_name ).value
1423
1423
flow = flow_pass .get ((curr , i_name ), 0 )
1424
1424
1425
- if i not in visited and capacity - flow > 0 :
1425
+ if i_name not in visited and capacity - flow > 0 :
1426
1426
visited [i_name ] = True
1427
1427
parent [i_name ] = curr
1428
1428
stack .append (i_name )
1429
1429
1430
- if t not in parent and t ! = s :
1430
+ if t not in parent and t = = s :
1431
1431
return 0 , {}
1432
-
1432
+
1433
1433
curr = t
1434
1434
path_flow = float ('inf' )
1435
1435
if t == s :
@@ -1440,7 +1440,7 @@ def _find_path_dfs(graph, s, t, flow_pass):
1440
1440
flow = flow_pass .get ((prev , curr ), 0 )
1441
1441
path_flow = min (path_flow , capacity - flow )
1442
1442
curr = prev
1443
-
1443
+
1444
1444
return path_flow , parent
1445
1445
1446
1446
def _max_flow_ford_fulkerson_ (graph , s , t ):
@@ -1477,7 +1477,7 @@ def _max_flow_ford_fulkerson_(graph, s, t):
1477
1477
1478
1478
if s not in graph .vertices or t not in graph .vertices :
1479
1479
raise ValueError ("Source or sink not in graph." )
1480
-
1480
+
1481
1481
ans = 0
1482
1482
flow_pass = {}
1483
1483
@@ -1492,10 +1492,8 @@ def _max_flow_ford_fulkerson_(graph, s, t):
1492
1492
curr = t
1493
1493
while curr != s :
1494
1494
pre = parent [curr ]
1495
- fp = flow_pass .get ((pre , curr ), 0 )
1496
- flow_pass [(pre , curr )] = fp + path_flow
1497
- fp = flow_pass .get ((curr , pre ), 0 )
1498
- flow_pass [(curr , pre )] = fp - path_flow
1495
+ flow_pass [(pre , curr )] = flow_pass .get ((pre , curr ), 0 ) + path_flow
1496
+ flow_pass [(curr , pre )] = flow_pass .get ((curr , pre ), 0 ) - path_flow
1499
1497
curr = pre
1500
-
1501
- return ans
1498
+
1499
+ return ans
0 commit comments