Question
You are provided a network of train stations and, for a given station outside of this network ( x ), you know the minimum fare
You are provided a network of train stations and, for a given station outside of this network (x), you know the minimum fare for reaching each in-network station from x, and you also know the minimum fare for returning to x from any in-network station. You are also given a list of 2-way dedicated cycling routes connecting pairs of in-network stations. Complete the function, cheapCycling, so that it efficiently finds the cheapest cyling journey and returns the pair of distinct in-network stations corresponding to this journey. Here, a journey consists of 1) arrival at an in-network station from x, 2) some amount of cost-free cycling using dedicated routes, and 3) return to x from an in-network station which is distinct from the arrival station. The train stations are numbered from 0 to N-1, and the function is provided two N-element lists as input (Slist and Clist). The ith element of Slist contains two numbers the minimum arrival and return fares for routes between stations i and x. Clist is an adjacency list. Its ith element contains a list of integers which correspond to in-network stations that can be reached directly by bicycle from station i.
Note: You are not allowed to use heap
Code provided:
def cheapCycling(SList,CList):
"""
Find first and last stations for cheapest cycling trip
Input:
Slist: list whose ith element contains cheapest fare for arrival at and
return from the ith station (stored in a 2-element list or tuple)
Clist: list whose ith element contains a list of stations which can be
cycled to directly from station i
Stations are numbered from 0 to N-1 with N = len(Slist) = len(Clist)
Output:
stations: two-element list containing first and last stations of journey
"""
#Add code here
stations=[None,None] #modify
return stations
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started