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

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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.

Sample Input 0
5 8 10
4 1 4
432
1 0 3
3 1 1
0 33
3 2 1
2 3 1
0 26
03
4 1
14
23
43
24
30
02
34
44
Sample Output 0
0->3: 3
4->1: 3
1->4: None
2->3: 1
4->3: 2
2->4: None
3->0: 4
0->2: 4
3->4: None
4->4: 0
Transcribed Image Text:Sample Input 0 5 8 10 4 1 4 432 1 0 3 3 1 1 0 33 3 2 1 2 3 1 0 26 03 4 1 14 23 43 24 30 02 34 44 Sample Output 0 0->3: 3 4->1: 3 1->4: None 2->3: 1 4->3: 2 2->4: None 3->0: 4 0->2: 4 3->4: None 4->4: 0
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Please show the complete code, it appears to be cut off in the picture.

Also, can this be done without importing inf from math?

Solution
Bartleby Expert
SEE SOLUTION
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY