implemented max flow