shithub: puzzles

Download patch

ref: 00e23909f8599686ae8aa975a7f5a443a500516f
parent: f6b2f47ef3feca86b0d16c28b607acdea5fc6235
author: Stefan Bühler <stbuehler@web.de>
date: Sat Oct 7 19:21:45 EDT 2017

fix loop condition

prev[sink] == 0 means there was a path found with the last step being a
forward edge to the sink, and the edge being at index 0 in the array.

This is a valid path (the same as any other path indicated by prev[sink]
> 0).

--- a/maxflow.c
+++ b/maxflow.c
@@ -80,7 +80,7 @@
 	/*
 	 * Now do the BFS loop.
 	 */
-	while (head < tail && prev[sink] <= 0) {
+	while (head < tail && prev[sink] < 0) {
 	    from = todo[head++];
 
 	    /*