Given a graph with V vertices, perform at most V-1 cycles.
Declare the array d[V]. The shortest distance from the starting point C to the vertex i is d[i]. The
array is initialized as:
distance | ∞ | ∞ | 0 | ∞ | ∞ | ∞ |
---|---|---|---|---|---|---|
vertex | A | B | C | D | E | F |
Repeat the following process V-1 times, if you fail to optimize in a certain process, you can exit early:
examine the vertex i one by one (if d[i]==∞ then skip), on the outgoing edge, judge it as Whether the intermediary can make the distance to the target vertex smaller, and if so, update the table.