cascading failure in lattice network, rewrite in c, way much faster than the python version before