Advertisement
shek_shek

396

Jun 22nd, 2015
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5. #define forn(i, n) for (int i = 0; i < (n); i++)
  6.  
  7. const int INF = 1000 * 1000 * 1000;
  8.  
  9. int a[100][100];
  10.  
  11. int main () {
  12. #ifdef _DEBUG
  13.     freopen("input.txt", "r", stdin);
  14.     freopen("output.txt", "w", stdout);
  15. #endif
  16.     int n;
  17.     cin >> n;
  18.  
  19.     forn (i, n) {
  20.         forn (j, n) {
  21.             cin >> a[i][j];
  22.             if (a[i][j] == 0) {
  23.                 a[i][j] = INF;
  24.             }
  25.             if (a[i][i] > 0)
  26.                 a[i][i] = 0;
  27.         }
  28.     }
  29.     forn(k, n)
  30.         forn(i, n)
  31.             forn(j, n)  
  32.                 if (a[i][k] < INF && a[k][j] < INF)
  33.                     a[i][j] =
  34.                     min(a[i][j], (1ll * a[i][k] + 1ll * a[k][j] < -INF ? -INF : a[i][k] + a[k][j]));
  35.  
  36.     forn(k, n)
  37.         forn(i, n)
  38.             forn(j, n)
  39.                 if (a[i][k] < INF && a[k][k] < 0 && a[k][j] < INF)
  40.                     a[i][j] = -INF;
  41.    
  42.     forn (i, n) {
  43.         forn (j, n) {
  44.             if (a[i][j] == INF)
  45.                 cout << 0 << " ";
  46.             else
  47.                 if (a[i][j] == -INF)
  48.                     cout << 2 << " ";
  49.                 else
  50.                     cout << 1 << " ";
  51.  
  52.         }
  53.         cout << endl;
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement