Using graph to calculate build path