cpp version for computing flowweb cost