Fix bug with possible empty graphs in Alg1