Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int edmondsKarp(int startNode, int endNode)
- {
- int maxFlow=0;
- while(true)
- {
- // we find an augmented path and the maximum flow corresponding to it
- int flow=bfs(startNode, endNode);
- // if we can't find anymore paths the flow will be 0
- if(flow==0)
- {
- break;
- }
- maxFlow +=flow;
- int currentNode=endNode;
- // we update the passed flow matrix
- while(currentNode != startNode)
- {
- int previousNode = parentsList[currentNode];
- flowPassed[previousNode][currentNode] += flow;
- flowPassed[currentNode][previousNode] -= flow;
- currentNode=previousNode;
- }
- }
- return maxFlow;
- }
Advertisement
Add Comment
Please, Sign In to add comment