/// <Summary>
/// The single-source shortest path algorithm in the directed acyclic graph
/// </Summary>
Public class dag_shortest_paths
{
/// <Summary>
/// Single-source shortest path in a directed acyclic graph
/// </Summary>
/// <Param name = "G"> directed acyclic graph </param>
/// <Param name = "S"> Source Vertex S </param>
Public void dagshortestpaths (Graphic g, node S)
{
Graphicsearchalg thegs = new graphicsearchalg ();
// Obtain the topological sorting
VaR thenodes = thegs. topologicalsort (g );
Singlesourcepath thessp = new singlesourcepath ();
// Initialization Diagram
Thessp. initializegraphic (G, S );
Foreach (node thenode in thenodes)
{
Foreach (VAR theadjnode in thenode. adjnodes)
{
// Use relaxation technology.
Thessp. Relax (theadjnode. value );
}
}
}
}
In the graph algorithm, the representation of the adjacent table can indeed improve the time complexity, but the representation of the adjacent matrix is conducive to the calculation of scale. You need to select the two based on the actual situation. In the subsequent largest stream and other algorithms, the two can be combined to give full play to their respective advantages.