SHARE
TWEET

Untitled

a guest Oct 21st, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. ifstream f("warshall.in");
  5. ofstream g("warshall.out");
  6.  
  7. int a[100][100],n,m;
  8.  
  9. void construire ()
  10. {
  11.     int x,y;
  12.     f>>n>>m;
  13.     for(int i=1; i<=m; i++)
  14.     {
  15.         f>>x>>y;
  16.         a[x][y]=1;
  17.     }
  18. }
  19. void afisare()
  20. {
  21.     int i,j;
  22.     for(i=1; i<=n; i++)
  23.     {
  24.         for(j=1; j<=n; j++)
  25.             g<<a[i][j]<<" ";
  26.         g<<" \n";
  27.     }
  28.     g<<"\n";
  29. }
  30. void warshall()
  31. {
  32.     int i,j,k;
  33.     for(k=1; k<=n; k++)
  34.     {
  35.         for(i=1; i<=n; i++)
  36.         {
  37.             for(j=1; j<=n; j++)
  38.                 if(a[i][j]==0 && i!=k && j!=k)
  39.                     a[i][j]=a[i][k]*a[k][j];
  40.         }
  41.  
  42.     }
  43.  
  44. }
  45. int main()
  46. {
  47.     construire();
  48.     afisare();
  49.     warshall();
  50.     g<<"DUPA : \n";
  51.     afisare();
  52.     return 0;
  53. }
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