The course need a software implementation of this algorithm. But stuck at the stage of restoring the path to the vertices, help, please.

```
static final double inf = double.positive_infinity;
Public Static Void BellManford (Double [] [] z, Int Start, Int End) {
INT VERTICESCOUNT = Z.Length;
Double [] q = new double [verticescount];
ArrayList & LT; Double & GT; labels = new arraylist & lt; & gt; ();
For (int i = 0; i & lt; verticescount; i ++) {
q [i] = inf;
}
q [start - 1] = 0.0;
for (int k = 0; k & lt; = verticescount - 1; k ++) {
For (int i = 0; i & lt; verticescount; i ++) {
For (int j = 0; j & lt; verticescount; j ++) {
labels.add (q [j] + z [j] [i]);
}
q [i] = minofarray (labels);
labels.clear ();
}
}
System.Out.printLN (Q [END - 1]);
}
Public Static Double Minofarray (ArrayList & LT; Double & GT; Array) {
Double min = inf;
For (int i = 0; i & lt; array.size (); i ++) {
if (min & gt; array.get (i))
min = array.get (i);
}
RETURN MIN;
}
```

## Answer 1

At the moment of triggering the condition `if (min & gt; array.get (i)) `

Record to the additional list `PREDS `

number `I `

(local `I `

`minofarray `

!!) The best ancestor for the vertex `i `

(local `i `

cycle `FOR (int i = 0; I & LT; VerticesCount; I ++) `

).

At the end of the work to find the path to the top of `q `

take her ancestor `preds [q] `

, then his ancestor, and so unwind before the initial vertex