Maxflow algorithm