this might be of some use....

http://www.wikipedia.org/wiki/Dijkstra%27s_algorithm