Пример #1
0
int main() {
    TGraph graph(5);
    graph.Insert(0, 1, 6);
    graph.Insert(0, 3, 7);
    graph.Insert(1, 2, 5);
    graph.Insert(1, 3, 8);
    graph.Insert(1, 4, -4);
    graph.Insert(2, 1, -2);
    graph.Insert(3, 2, -3);
    graph.Insert(3, 4, 9);
    graph.Insert(4, 2, 7);
    graph.Insert(4, 0, 2);

    cout << "DFS: ";
    graph.Dfs();
    cout << endl;

    cout << "BFS: ";
    graph.Bfs();
    cout << endl;

    TGraph copy = graph.Copy();

    cout << "copy DFS: ";
    copy.Dfs();
    cout << endl;

    cout << "copy BFS: ";
    copy.Bfs();
    cout << endl;

    int src = 0;
    cout << "Bellman Ford from src " << src << endl;
    graph.BellmanFord(src);

    TGraph nonNegGraph(5);
    nonNegGraph.Insert(0, 1, 10);
    nonNegGraph.Insert(0, 3, 5);
    nonNegGraph.Insert(1, 2, 1);
    nonNegGraph.Insert(1, 3, 2);
    nonNegGraph.Insert(2, 4, 4);
    nonNegGraph.Insert(3, 1, 3);
    nonNegGraph.Insert(3, 2, 9);
    nonNegGraph.Insert(3, 4, 2);
    nonNegGraph.Insert(4, 0, 7);
    nonNegGraph.Insert(4, 2, 6);

    cout << "non-neg BFS: ";
    nonNegGraph.Bfs();
    cout << endl;

    cout << "Dijkstra from src " << src << endl;
    nonNegGraph.Dijkstra(src);

    return 0;
}