Maximum Flow algorithm

Below are implementations of the Ford-Fulkerson algorithm to compute the maximum flow in a graph with integer capacities. Breadth first search is used to find paths from the source to the target which makes this the Edmonds-Karp algorithm. To learn about this topic I recommend reading the references. Continue reading

Read input of unknown length

Problem:
Suppose you are given the following input:

5 22 9 813 13
77 98 93 51
5 3 1 5 7 1 3
9 1

Your task is to print out the sum of the numbers in each line, e.g. the sum for the first line is

5 + 22 + 9 + 813 + 13 = 862

So the output should be:

862
319
25
10

The problem here is that you don’t know how many lines you are given and how many numbers there are in each line. How can you solve this problem in Python and C++?

Continue reading