Optimize edmunds karp max_flow algorithm