fixed so that it returns false for graphs without cycles