Advertisement blocking software were detected ;( Please add this webpage to whitelist.

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.



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]




cost [the minimum transportation cost from city NAME1 to city NAME2 (one per line)]




2 1
3 3
1 1
3 1
4 4
1 3
2 1
4 1
2 4
3 1
gdansk warszawa
bydgoszcz warszawa



Warning: large Input/Output data, be careful with certain languages

hide comments
ARUN P: 2015-09-28 20:07:31

Are the cities given in order according to their indices?

Rohit Agarwal: 2015-09-04 22:11:33

Wow. Really nice question. It teaches the importance of optimization.
Finally AC after 3 TLE's.
Optimizations I did:-
1. Fast I/O: use getchar_unlocked for all the input
2. Use Djikstra with min heap.
3. Avoid using a graph like this graph[MAX][MAX].. becasue this wil create the graph which will take order of 10power8. You need something around O(10pow7) for AC. Go for edgelist representation.

To check your Time Limit.. solve TSHPATH. the time limit is ~ 5secs.

sri varun: 2015-07-26 16:36:35

Last edit: 2015-07-26 16:38:25
sujit yadav: 2015-06-23 21:15:36

0.53 :) c++ rocks

Kishore H Patel: 2015-04-14 13:36:45

JAVA users: Don't use iterator for loop, instead use explicit iterator for loop. I mean use for(int i = 0; i < list.size(); i++) and not for(int i : list)

Last edit: 2015-04-14 13:37:43
getting started: 2015-03-19 15:12:45

2 tle , 2 re , 4 wa, finally acc .... smile restored

childe: 2015-02-21 07:19:38

I am curious how they made it within 0.00s. it takes more than it for just reading the input.

Satyaanveshi: 2015-02-15 03:32:19

I got A/C using C++ 4.9 but TLE with 4.3.2. My running time was 1.44.

Last edit: 2015-02-27 09:33:29
Rahul Lingala: 2014-12-27 18:45:10

Exact 1.50s!
Use TSHPATH to optimize your solution.
Use C++ 4.0.0-8
I wonder how people got AC in 0.00 seconds :/

Last edit: 2015-05-18 22:36:52
DivineAtheist: 2014-12-27 01:47:09

hard to get AC...Use TSHPATH to experiment...

Added by:Darek Dereniowski
Time limit:1.5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel Pentium G860 3GHz)
Resource:DASM Programming League 2003 (problemset 11)