SHPATH  The Shortest Path
You are given a list of cities. Each direct connection between two cities has its transportation cost (an integer bigger than 0). The goal is to find the paths of minimum cost between pairs of cities. Assume that the cost of each path (which is the sum of costs of all direct connections belongning to this path) is at most 200000. The name of a city is a string containing characters a,...,z and is at most 10 characters long.
Input
s [the number of tests <= 10] n [the number of cities <= 10000] NAME [city name] p [the number of neighbours of city NAME] nr cost [nr  index of a city connected to NAME (the index of the first city is 1)] [cost  the transportation cost] r [the number of paths to find <= 100] NAME1 NAME2 [NAME1  source, NAME2  destination] [empty line separating the tests]
Output
cost [the minimum transportation cost from city NAME1 to city NAME2 (one per line)]
Example
Input: 1 4 gdansk 2 2 1 3 3 bydgoszcz 3 1 1 3 1 4 4 torun 3 1 3 2 1 4 1 warszawa 2 2 4 3 1 2 gdansk warszawa bydgoszcz warszawa Output: 3 2
Warning: large Input/Output data, be careful with certain languages
hide comments
hitesh87:
20190517 19:43:35
@harshraj22aug Didn't try it but it might certainly increase TC. e.g if no. of query are small like 1,2 etc then Floyd Warshall Algorithm will take O(V^3) while Djikstra can handle in O(V^2).


harshraj22aug:
20190517 12:58:53
Recently I came to know about Floyd Warshall Algorithm, which gives the shortest path between all pairs of points in the graph. I wonder why isn't anyone using that here, rather than doing Dijkstra for every query ?


Narendra yadav:
20190419 22:14:44
@alphacoder101:


gs959_me:
20190407 08:59:40
Phew!! got AC with 1.29 sec..


alphacoder101:
20190206 06:29:38
AC in one go.


surajgoel1225:
20190103 18:25:03
Simpe Djikstra,using priority_queue in c++. 

marethyu1:
20181225 20:24:35
That was close! AC in 0.94 

vivek_rathi:
20181216 11:45:16
Don't use set , use priority queue to save yourself from TLE


nikbansal_123:
20181008 00:15:39
TIP: Use the priority_queue implementation of Dijkstra to avoid TLE instead of set


ameyanator:
20180924 08:05:51
Hello World in Dijkstra 
Added by:  Darek Dereniowski 
Date:  20040510 
Time limit:  1.5s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All 
Resource:  DASM Programming League 2003 (problemset 11) 