n-dimensional network flow solver