mitkonikov

MatricaMendo

Mar 10th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <bits/stdc++.h>  
  2.     using namespace std;  
  3.      
  4.     int main()  
  5.     {  
  6.         int n;  
  7.         cin >> n;  
  8.      
  9.         int dist[301][301];  
  10.      
  11.         for (int i=0; i<n; i++) {  
  12.             for (int j=0; j<n; j++) {  
  13.                 cin >> dist[i][j];  
  14.             }  
  15.         }  
  16.      
  17.      
  18.         for (int i=0; i<n; i++) {  
  19.             for (int j=i+1; j<n; j++) {  
  20.                 for (int k=0; k<n; k++) {  
  21.      
  22.                     if (k!=i && k!=j && dist[i][k] + dist[k][j] < dist[i][j]) {  
  23.                         cout << "GRESHKA" << endl;  
  24.                         return 0;  
  25.                     }  
  26.                 }  
  27.             }  
  28.         }  
  29.      
  30.      
  31.         long long sum = 0;  
  32.         for (int i=0; i<n; i++) {  
  33.             for (int j=i+1; j<n; j++) {  
  34.      
  35.                 bool important = true;  
  36.                 for (int k=0; k<n && important; k++) {  
  37.      
  38.                     if (k!=i && k!=j && dist[i][k] + dist[k][j] == dist[i][j]) {  
  39.                         //nema potreba od vakvo rebro  
  40.                         important = false;  
  41.                     }  
  42.                 }  
  43.      
  44.                 if (important) {  
  45.                     sum += dist[i][j];  
  46.                 }  
  47.             }  
  48.         }  
  49.      
  50.         cout << sum << endl;  
  51.         return 0;  
  52.     }
Advertisement
Add Comment
Please, Sign In to add comment