Hm,
ich steck nicht so dick drin im Thema, aber sollte eine BFS nicht ausreichen.
Ausführlich mitgeschrieben Start bei v12
Removing node 12 from the queue ...,
Visiting node 3, setting its distance to 1 and adding it to the queue,
Visiting node 11, setting its distance to 1 and adding it to the queue,
Removing node 3 from the queue ...,
Visiting node 1, setting its distance to 2 and adding it to the queue,
Visiting node 2, setting its distance to 2 and adding it to the queue,
Visiting node 4, setting its distance to 2 and adding it to the queue,
Removing node 11 from the queue ...,
Removing node 1 from the queue ...,
Visiting node 5, setting its distance to 3 and adding it to the queue,
Visiting node 6, setting its distance to 3 and adding it to the queue,
Removing node 2 from the queue ...,
Removing node 4 from the queue ...,
Visiting node 9, setting its distance to 3 and adding it to the queue,
Visiting node 10, setting its distance to 3 and adding it to the queue,
Removing node 5 from the queue ...,
Removing node 6 from the queue ...,
Visiting node 7, setting its distance to 4 and adding it to the queue,
Visiting node 8, setting its distance to 4 and adding it to the queue,
Removing node 9 from the queue ...,
Removing node 10 from the queue ...,
Removing node 7 from the queue ...,
Removing node 8 from the queue ...
ergibt
BFSdist = {{12}, 2, 2, 1, 2, 3, 3, 4, 4, 3, 3, 1, 0}
Taugt das als Einstieg?