Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- const int inf = 100;
- // liczba rzedow = ilosc krawedzi
- int arcs[8][3] = {
- {6, 4, 5},
- {6, 5, 4},
- {5, 3, -2},
- {5, 2, 1},
- {4, 3, 3},
- {2, 1, 1},
- {3, 2, -3},
- {3, 1, 3}
- };
- // wielkosc tablicy = ilosc wierzcholkow
- int nodes[6] = {0, inf, inf, inf, inf, inf};
- int pi[6] = {0, 0, 0, 0, 0, 0};
- for (int i = 0; i < 5; i++) {
- for (auto & arc : arcs) {
- int start = arc[0];
- int end = arc[1];
- int value = arc[2];
- if (nodes[start - 1] > value + nodes[end - 1]) {
- nodes[start - 1] = value + nodes[end - 1];
- pi[start] = end;
- }
- }
- }
- for (int node : nodes) {
- cout << node << " ";
- }
- cout << "\npi\n";
- for (int i : pi) {
- cout << i << " ";
- }
- for (auto & arc : arcs) {
- int start = arc[0];
- int end = arc[1];
- int value = arc[2];
- if (nodes[start - 1] > value + nodes[end - 1]) {
- cout << "error";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement