Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. const int inf = 100;
  10. // liczba rzedow = ilosc krawedzi
  11. int arcs[8][3] = {
  12. {6, 4, 5},
  13. {6, 5, 4},
  14. {5, 3, -2},
  15. {5, 2, 1},
  16. {4, 3, 3},
  17. {2, 1, 1},
  18. {3, 2, -3},
  19. {3, 1, 3}
  20. };
  21. // wielkosc tablicy = ilosc wierzcholkow
  22. int nodes[6] = {0, inf, inf, inf, inf, inf};
  23. int pi[6] = {0, 0, 0, 0, 0, 0};
  24. for (int i = 0; i < 5; i++) {
  25. for (auto & arc : arcs) {
  26. int start = arc[0];
  27. int end = arc[1];
  28. int value = arc[2];
  29. if (nodes[start - 1] > value + nodes[end - 1]) {
  30. nodes[start - 1] = value + nodes[end - 1];
  31. pi[start] = end;
  32. }
  33. }
  34. }
  35.  
  36. for (int node : nodes) {
  37. cout << node << " ";
  38. }
  39.  
  40. cout << "\npi\n";
  41. for (int i : pi) {
  42. cout << i << " ";
  43. }
  44.  
  45. for (auto & arc : arcs) {
  46. int start = arc[0];
  47. int end = arc[1];
  48. int value = arc[2];
  49. if (nodes[start - 1] > value + nodes[end - 1]) {
  50. cout << "error";
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement