Advertisement
Guest User

drumulRoyWarshall

a guest
Mar 20th, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. int a[20][20],n,m;
  5. int i,j,k;
  6. //----------------------------------------------------------------------
  7. void citire()
  8. {
  9.     ifstream f("date.txt");
  10.     int x,y;     f>>n>>m;
  11.     cout<<"noduri="<<n<<endl;
  12.     cout<<"muchii="<<m<<endl;
  13.     for(i=1;i<=m;i++)
  14.     {
  15.         f>>x>>y;
  16.         cout<<"x("<<i<<"): "<<x<<endl; //cin>>x;
  17.         cout<<"y("<<i<<"): "<<y<<endl; //cin>>y;
  18.             a[x][y]=1;      // Graf Orientat
  19.     }
  20. }
  21. //----------------------------------------------------------------------
  22. void rw()
  23. {
  24.     for(k=1;k<=n;k++)
  25.         for(i=1;i<=n;i++)
  26.             for(j=1;j<=n;j++)
  27.                 if(a[i][j]==0)  a[i][j]=a[i][k]*a[k][j];
  28. }
  29. //----------------------------------------------------------------------
  30. void afisare()
  31. {
  32.     cout<<endl<<"Matricea de adiacenta este: "<<endl;
  33.     for(i=1;i<=n;i++)
  34.         {
  35.             for(j=1;j<=n;j++)   cout<<a[i][j]<<" ";
  36.             cout<<endl;
  37.         }
  38.     cout<<endl;
  39. }
  40. //----------------------------------------------------------------------
  41. int main()
  42. {
  43.     citire();
  44.     rw();
  45.     afisare();
  46.     return 1337;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement