If you take `inv(-D)` where D is the dependency matrix, it should solve this in one fell swoop even in the presence of cycles. We can either use the eigenvalues or multiply that matrix by the indicator matrix of required packages.