I have a problem with a variation of a DFS which has ALL VERTICES TO A DISTANCE GIVEN FROM VERTICE ORIGIN, for this I used a DFS algorithm which looks for all possible paths given a source vertex and a destination vertex, to recycle code I place the origin in the section of the destination paramentro and with a traverse all the vertices placing them as the origin parameter in the method, to this I add a sum of distances and when it meets the two conditions it shows a result that is when it reaches the destination + x distance returns that result, my problem is that sometimes does not give the correct result and I do not know why ...
static void DFS_S2(vertice origen, vertice destino, grafo graf,float distancia, float suma, string path)
{
path = (path == String.Empty ? path : $"{path},") + origen.nombre;
if (origen.nombre == destino.nombre&distancia==suma)
{
string[] datos2 = path.Split(new char[] { ',' });
Console.WriteLine(datos2[0]);
}
else
{
for (int con = 0; con < origen.adyacencias.Length; con++)
{
var visitado = Regex.IsMatch(path, $@"\b{graf.vertices[con].nombre}\b");
if (origen.adyacencias[con] > 0 && !visitado)
{
suma = suma + origen.adyacencias[con];
DFS_S2(graf.vertices[con], destino, graf, distancia, suma, path);
}
}
}
}