Computer scienceAlgorithms and Data StructuresAlgorithmsGraph algorithmsShortest path algorithms

Comparing the shortest path algorithms

Jack and Jill

Report a typo

Jack and Jill are participants in a competitive programming contest. As you may know, in competitive programming, the solutions should be not only correct but also quick: the winner's code compiles the fastest and solves the task correctly. The task goes as follows:

John is a game developer. He is trying to make a multi-level car racing game, therefore, the 'CPU player' should make optimal decisions at the hardest level. The playground includes the red starting point, blue gas stations, and weighted roads as shown below. Their weights may vary depending on what is found at the stations. John has to calculate the weight of the shortest paths from the starting spot 00 to all the stations.

Dijkstra or Bellman-Ford?

Jack decided to apply the array implementation of Dijkstra's algorithm. Meanwhile, Jill used the Bellman-Ford algorithm. What will be the output of both solutions? Who will win the competition?

If none of them has solved the task correctly, write NONE. If both implementations work correctly and take the same amount of time, output BOTH. The first line contains Jack's expected output, the second one – Jill's answer, and the third line reveals the winner's name. The shortest distances in the array should follow the following order: d1,d2,d3,d4,d5.d_1, d_2, d_3, d_4, d_5. If the algorithms find the presence of a negative cycle, write NC instead.

Answer format examples:

3 6 2 -7 1
3 6 2 -7 1
Jack
3 7 1 4 2
NC
Jill
2 6 -1 -2 4
0 -2 4 5 -2
NONE
Enter a short text
___

Create a free account to access the full topic