On the inverse problem of the calculus of variations for ordinary differential equations