In this assignment, you will implement the Edmonds-Karp maximum flow algorithm, to compute the maximum flow between vertex 0, and the highest numbered vertex in the graph.

The input will be the same format as with the prior graph assignments, with the edge length meaning the edge capacity, AND THE GRAPH IS DIRECTED. If there is an edge from A to B, then it only goes from A to B, and not back.

You will probably want to re-use the data structures from the connected components assignment. When you create a pair of edges (one for each direction), you can link them together, and use the "backwards" edge to hold residual capacity.

The algorithm is fairly simple -- use BFS to find a path from 0 to the highest vertex. Back-trace the path to find the capacity of the path, then trace it again to remove forward capacity, and put it on to the reverse direction. Keep doing this until you have the flow....

Print out the flow of the graph when you're done (don't print anything else out, please!).

Here are some simple examples:

2 1
0 1 100

This first example is simply an edge from vertex 0 to vertex 1, with a capacity of 100. Your program should say "100."

3 2
0 1 10
1 2 5

The second example has a connection from vertex 0 to 1 with a capacity of 10, and then from 1 to 2 with a capacity of 5. The flow you can get is 5, so print that.

2 2
0 1 5
0 1 6

Two edges from 0 to 1, with a total capacity of 11

2 2
1 0 10
1 0 3

Two edges, but they go from 1 to 0, so no flow, print "0"

8 9
0 1 1
1 2 1
2 3 1
0 4 1
4 3 1
4 5 1
5 6 1
6 7 1
3 7 1

If you use BFS (and you should), the first path you find should be 0->4->3->7. This will cause the 4->3 edge to have capacity in the reverse direction. The second path should be 0->1->2->3->4->5->6->7, for a total capacity of 2.