FEgor04

Floyd

Oct 9th, 2019
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.01 KB | None | 0 0
  1. /*
  2. █████████████.....██████....██.........█....██████████....██.........██.
  3. ██.........██.......██......█.█........█....██......██.....██.......██..
  4. ██.........██.......██......█..█.......█....██......██......██.....██...
  5. ██.........██.......██......█...█......█....██......██.......██...██....
  6. ██.........██.......██......█....█.....█....██......██........██.██.....
  7. ██.........██.......██......█.....█....█....██......██.........███......
  8. █████████████.......██......█.....█....█....██████████.........███......
  9. ██..................██......█......█...█....██......██.........███......
  10. ██..................██......█......█...█....██......██.........███......
  11. ██..................██......█.......█..█....██......██.........███......
  12. ██..................██......█.......█..█....██......██.........███......
  13. ██..................██......█........█.█....██......██.........███......
  14. ██..................██......█........█.█....██......██.........███......
  15. ██................██████....█.........██....██......██.........███......
  16. */
  17. #include <bits/stdc++.h>
  18. // #define DEBUG
  19. using namespace std;
  20. typedef long long ll;
  21. typedef long double ld;
  22. typedef vector<ll> vll;
  23. typedef vector<int> vi;
  24. typedef pair<int, int> pii;
  25. typedef pair<ll, ll> pll;
  26. #define FF first
  27. #define SS second
  28. #define watch(x) cerr << (#x) << " is " << x << endl
  29.  
  30. ld P[101][101];
  31.  
  32. const ll INF = 1ll<<40;
  33.  
  34. int main() {
  35.     // ios_base::sync_with_stdio(0);
  36.     // cin.tie(NULL);
  37.     #ifdef DEBUG
  38.     #else
  39.         freopen("input.txt", "r", stdin);
  40.         freopen("output.txt", "w", stdout);
  41.     #endif
  42.     int n, m;
  43.     cin >> n >> m;
  44.     ld temp;
  45.     for(int i = 0; i < n; i++) {
  46.         for(int j = 0; j < n; j++) {
  47.             cin >> temp;
  48.             if(temp != -1001) {
  49.                 P[i][j] = temp;
  50.             }
  51.             else {
  52.                 P[i][j] = INF;
  53.             }
  54.             // cout << P[i][j] << " ";
  55.         }
  56.         // cout << endl;
  57.     }
  58.     // for(int i = 0; i < n; i++) {
  59.     //  for(int j = 0; j < n; j++) {
  60.     //      cout << P[i][j] << " ";
  61.     //  }
  62.     //  cout << endl;
  63.     // }
  64.     // cout << "\n\n\n";
  65.     for(int k = 0; k < n; k++) {
  66.         for(int i = 0; i < n; i++) {
  67.                 for(int j = 0; j < n; j++) {
  68.                     // cout << P[i][j] << "\n";
  69.                     // cout << P[i][k] + P[k][j] << "\n";
  70.                     P[i][j] = min( P[i][j] , P[i][k] + P[k][j] );
  71.                 }
  72.         }
  73.     }
  74.     // for(int i = 0; i < n; i++) {
  75.     //  for(int j = 0; j < n; j++) {
  76.     //      cout << P[i][j] << " ";
  77.     //  }
  78.     //  cout << endl;
  79.     // }
  80.     int l, r;
  81.     for(int i = 0; i < m; i++) {
  82.         cin >> l >> r;
  83.         l--;
  84.         r--;
  85.         if(P[l][r] != INF) {
  86.             cout << P[l][r] << "\n";
  87.         }
  88.         else {
  89.             cout << "No path\n";
  90.         }
  91.     }
  92.     return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment