In the calculus of variation they set up the problem as action S

where

and

In the case of finding the shortest distance between two points this makes sense but in the case of finding the path of least time as in a roller coaster shaped like a e Brachistochrone

I am not getting why the case of

applies?

How does this work in that case?