Flow algorithm. With correct answer!