Updated precompute to work on all graphs