You are traveling with your friends along the Geraldton coast with cities c0, c1, c2, ..., cn on the shore. You are starting in city c0 where a famous spa is and need to reach the airport situated in city cn, so you will visit each city c0, c1, c2, ..., cn in that order. In each city, you may swap the animal you are riding on, and the choices are a giraffe, a mammoth, an ant, an iguana, and a lemur, denoted G, M, A, I, L respectively. However, each city has its own rules for what kind of animal exchanges are allowed. For example, in some of the cities, you can swap a giraffe only for a lemur or an ant (and you cannot remain on your giraffe), in others, you can swap a mammoth only for a giraffe or decide to remain on your mammoth, and so on. You know all the rules of all the cities c1, ..., cn, expressed by a function R(i, a, b) where R(i, a, b) = 1 if in city ci one can swap animal a for animal b, and zero otherwise (a and b belong to the set {G, M, A, I, L}, and 1 ≤ i < n). You also know the speed v(a) in km/h (a ∈ {G, M, A, I, L}) of each of the five animals, as well as the distances d(i) in km between cities ci−1 and ci for all i = 1, 2, ..., n. Calculating a given value of R, v, or d can be done in O(1) time. You may begin your journey from c0 on any of the five animals. You need to choose which animals to use for each of the n trips between cities, such that your travel time is minimized and every animal swap is valid. Design an algorithm that determines the minimal amount of time (in hours) it will take to get from c0 to cn without making invalid swaps, as well as the animals required on each trip to achieve this time. Your algorithm must run in O(n) time.