Using f-values seems unnecessary to me. Using f(x)=x, the values just become 0,1,2,3,... In terms of computer memory, I don't think there is any advantage to using an f(x) other than f(x)=x. Also, you could think of having a boolean value assigned to each vertex: visited or unvisited. If all you care about are A and B, you don't need to keep track of the distances of each intermediate vertex.
A harder problem is when edges have unequal weight. For this Dijkstra's algorithm is one easy-to-implement option.