Skip to content

Commit 22d5ba3

Browse files
author
gangs2314
committed
fix: correct push-relabel active condition and johnson test expectation
1 parent d063a89 commit 22d5ba3

2 files changed

Lines changed: 2 additions & 5 deletions

File tree

graphs/push_relabel.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ def max_flow(self, source: int, sink: int) -> int:
9191
pushed = False
9292
for v in range(n):
9393
if self.push(u, v):
94-
if (
95-
v not in (source, sink)
96-
and self.excess[v] == self.excess[u] + 1
97-
):
94+
if v not in (source, sink) and self.excess[v] > 0:
9895
active.append(v)
9996
pushed = True
10097
if self.excess[u] == 0:

graphs/tests/test_graph_algorithms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_basic_graph(self):
6767
4: [],
6868
}
6969
dist = johnsons_algorithm(graph, 5)
70-
assert dist[0][4] == -1 # 0->1->3->4 = -5+3+2 = 0, wait let me check
70+
assert dist[0][4] == 0 # 0->1->3->4 = -5+3+2 = 0, wait let me check
7171
# Actually: 0->1 (-5), 1->2 (4), 2->4 (1) = 0, or 0->1->3->4 = 0
7272

7373
def test_negative_cycle(self):

0 commit comments

Comments
 (0)