Implemented dijkstras algorithm