Is there a better way of finding an element's position in an adjacency list of a graph than storing its position and then comparing the whole array to find it?(pairs are already used)
I have a weighted graph and lets say I know that from A I can go to B and has a cost of 5.I used a 2d vector of pairs to store this.
Ex:
A: B-5,C-6,D-7 (explanation : A goes to B with a cost of 5 , it also goes to C with a cost of 6 etc...)
B: G-6 ,W-6
H: V-5
A goes to B , B goes to G and W.
What I want to do is find a way to access the memory of B without having to store it in a temporary array.Which means that I will need to search it every time to find it.
Any ideas?
EDIT-This isn't homework exercise by the way.