80 likes | 180 Vues
d091: Urban Transport System. Po-Lung Chen Team Dont Block Me, National Taiwan University March 26, 2010. Problem Description (1/2). Given information of subway lines and bus lines. For each query find the minimum time traveling from source station to the destination station.
E N D
d091: Urban Transport System Po-Lung Chen Team Dont Block Me, National Taiwan University March 26, 2010
Problem Description (1/2) • Given information of subway lines and bus lines. • For each query find the minimum time traveling from source station to the destination station.
Problem Description (2/2) • Every bus line is numbered from 1 to 99. • Every subway line is numbered from ‘A’ to ‘Z’. • The number of stations on each line . • The average transfer and waiting time:
Input Specification 1 L 36 2 1 3 5 3 2 3 L K 3 5 7 6 6 3 3 3 5 1 Q 1 2 Q 1 7 E 6 The number of test cases. Bus line #36, 3 stops 1 3 2 Subway line #11, 4 stops (6->3->5->7) 5 2 Queries:1->2?1->7? End of queries 7
Graph Model • We view each as a node. • If a bus/subway line (line number ) passes from station A to station B, an edge is created with its weight equals the time this bus/subway travel from A to B. • If two bus/subway line (line number ) passes same station A, then an edge created with its cost 5 or 10 according to the average waiting time.
Solution • Once we constructed the graph, for each query just find the shortest path from source station (with any possible bus/subway line number) to destination. • We can use Dijkstra’s algorithm to solve this problem. • Moreover, we can use adjacent lists to store the information of nodes and edges on the graph.
Analysis • The number of nodes on the graph is equal to the sum of number of stations over all bus/subway lines, which is at most . • The degree of each node is at most . • Apply Dijkstra’s Algorithm with a heap we can solve this problem in . • With a Fibonacci heap (NOT recommended), we can achieve the time complexity .
Finally… Thanks for your attention!