PYTHON PROGRAMMING You want to travel with the Guardians of the Galaxy!! As a hero, you want to do good whenever it is needed, and so you wish to travel quickly to places where you are needed next. You and the Guardians continuously patrol the universe and its different sectors. Your spaceship can travel between sectors with hyperspace technology, which uses known wormholes between sectors. Each wormhole is a distortion of space-time, and as such, you might have a different sense of time after traveling to it. More specifically, by traveling to a wormhole, the local time at the sector where you will arrive
PYTHON PROGRAMMING
You want to travel with the Guardians of the Galaxy!! As a hero, you want to do good whenever it is needed, and so you wish to travel quickly to places where you are needed next. You and the Guardians continuously patrol the universe and its different sectors. Your spaceship can travel between sectors with hyperspace technology, which uses known wormholes between sectors. Each wormhole is a distortion of space-time, and as such, you might have a different sense of time after traveling to it. More specifically, by traveling to a wormhole, the local time at the sector where you will arrive can be less than or greater than the local time at the sector you just left! So, you can travel forwards or backwards in time by going through these wormholes. Your goal is to determine the "fastest” route between two sectors by passing through the most optimal set of wormholes. The universe and its network of wormholes is modeled by a graph, with vertices corresponding to distinct sectors in the universe, and edges representing the wormholes between sectors. Each edge is directed, i.e., the links are unidirectional. At the same time, each link adds a constant integer “time offset” if you use the wormhole in your travels. Also, if your source and destination sector is the same, then we can consider this as “0” time offset. Given a list of source sectors and corresponding destination sectors, your goal is to determine the fastest travel time from each source sector to its destination sector. By “fastest”, we mean the least time offset from when you started the journey until you commenced it. This means that “-10” is “faster” than “2”, since -10<2.
Input Format
Each test case starts with a line containing three integers V, E, and Q, denoting the number of vertices, edges, and queries, respectively. Note that vertices are identified with integers from 0 to V-1. E lines follow, each containing three integers s_i, d_i, l_i, denoting the source vertex, destination vertex, and latency; these three integers describe the ith edge. Q lines follow, each containing two vertices q_si, q_di, for which you must determine the total travel time T_i of the shortest path from vertex q_si to vertex q_di.
Constraints
2≤V≤100 V≤E≤1,000 1≤Q≤V^2 0≤s_i,d_i
Output Format
For each query vertex pair q_si, q_di, you must output a line containing q_si, q_di, and T_i. If q_di is not reachable from q_si, output “None” instead.
Step by step
Solved in 4 steps with 2 images
Please show the complete code, it appears to be cut off in the picture.
Also, can this be done without importing inf from math?