Constrained Shortest Paths in Terrains and Graphs