Advertisement
Guest User

celebru_Roy-Warshall

a guest
Mar 22nd, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //19 Sa se determine persoana cea mai celebra
  2. //dintr-un grup
  3. #include <iostream>
  4. #include <fstream>
  5. using namespace std;
  6. int a[20][20],n,m;
  7. int i,j,k;      int gr_int,gr_ext;
  8. //----------------------------------------------------------------------
  9. void citire()
  10. {
  11.     ifstream f("date.txt");
  12.     int x,y;     f>>n>>m;
  13.     cout<<"noduri="<<n<<endl;
  14.     cout<<"muchii="<<m<<endl;
  15.     for(i=1;i<=m;i++)
  16.     {
  17.         f>>x>>y;
  18.         cout<<"x("<<i<<"): "<<x<<endl;
  19.         cout<<"y("<<i<<"): "<<y<<endl;
  20.             a[x][y]=1;      // Graf Orientat
  21.     }
  22. }
  23. //----------------------------------------------------------------------
  24. void rw()
  25. {
  26.     for(k=1;k<=n;k++)
  27.         for(i=1;i<=n;i++)
  28.             for(j=1;j<=n;j++)
  29.                 if(a[i][j]==0)      a[i][j]=a[i][k]*a[k][j];
  30. }
  31. //----------------------------------------------------------------------
  32. void afisare()
  33. {
  34.     cout<<endl<<"Matricea de adiacenta este: "<<endl;
  35.     for(i=1;i<=n;i++)
  36.         {
  37.             for(j=1;j<=n;j++)   cout<<a[i][j]<<" ";
  38.             cout<<endl;
  39.         }
  40.     cout<<endl;
  41. }
  42. //----------------------------------------------------------------------
  43. int main()
  44. {
  45.     citire();
  46.     rw();
  47.     afisare();
  48.  
  49.    cout<<endl;
  50.    for(j=1;j<=n;j++)
  51.    {
  52.        gr_int=0;
  53.        gr_ext=0;
  54.      for(i=1;i<=n;i++)
  55.         {
  56.             if(a[i][j]==1) gr_int++;
  57.             if(a[j][i]==1) gr_ext++;
  58.         }
  59.        if(gr_int==n-1&&gr_ext==0)   cout<<"celebru "<<j<<" "<<endl;
  60.     }
  61.     return 1337;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement