Create a path graph for an actor to follow


I am trying to create an interactive map sort of game, where an army actor can be ordered to move to a province. What I am struggling with is how the actor should choose the best path as there might be several paths to the same destination of varying length. Quick research brought me to an idea to use a path graph, a graph showing the several provinces (represented as letters) with their connections to other provinces (as lines) and with the length of the path written over the line (a number). Now ideas are easy, the problem is that I’m not quite sure how best to implement it. I thought of having an array for each province linking all the other provinces with the length however for the actor to loop through each of these would be very demanding. Anyone here with a way to implement this or perhaps a better idea overall.

Example graph attached :wink:

Thank you!