SHARE
TWEET

Untitled

a guest Oct 15th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  main.cpp
  3. //  Lab1
  4. //
  5. //  Created by Marcin Włoczko on 03/10/2019.
  6. //  Copyright © 2019 Marcin Włoczko. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. using namespace std;
  11.  
  12. int main(int argc, const char * argv[]) {
  13.     int arcs[8][3] = {
  14.         {6, 4, 5},
  15.         {4, 3, 3},
  16.         {3, 1, 3},
  17.         {6, 5, 4},
  18.         {5, 2, 1},
  19.         {2, 1, 1},
  20.         {3, 2, -3},
  21.         {5, 3, -2},
  22.     };
  23.     int d[6] = {0, 100, 100, 100, 100, 100};
  24.     int pi[6] = {0, 0, 0, 0, 0, 0};
  25.  
  26.     for (int i = 1; i <= 5; i++) {
  27.         for (int j = 0; j <= 7; j++) {
  28.             int start = arcs[j][0] - 1;
  29.             int end = arcs[j][1] - 1;
  30.             int value = arcs[j][2];
  31.             if (d[start] > value + d[end]) {
  32.                 d[start] = value + d[end];
  33.                 pi[start] = end;
  34.             }
  35.         }
  36.     }
  37.  
  38.     for (int j = 0; j <= 7; j++) {
  39.         int start = arcs[j][0] - 1;
  40.         int end = arcs[j][1] - 1;
  41.         int value = arcs[j][2];
  42.         if (d[start] > value + d[end]) {
  43.             d[start] = value + d[end];
  44.             pi[start] = end;
  45.         }
  46.     }
  47.  
  48.     for (int j = 0; j <= 5; j++) {
  49.         cout << d[j] << " ";
  50.     }
  51.  
  52.     cout << "\n" << "pi" << "\n";
  53.     for (int j = 0; j <= 5; j++) {
  54.         cout << pi[j] << " ";
  55.     }
  56.  
  57.     return 0;
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top