Containing Cascading Failures In Networks: Applications To Epidemics And Cybersecurity