Advertisement
hegemon88676

nr muchii, noduri izolate, noduri pare, graf complet sau nu

May 4th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. int n,m,a[101][101];
  6. ifstream f("fmmviata.in");
  7.  
  8. void citire()
  9. {
  10.     int i,j;
  11.     f>>n;
  12.     while (f>>i>>j) {a[i][j]=a[j][i]=1;
  13.                      m++;}
  14. }
  15.  
  16. int gr(int nod)
  17. {
  18.     int x,s=0;
  19.     for(x=1;x<=n;x++)
  20.         s=s+a[nod][x];
  21.     return s;
  22.  
  23. }
  24.  
  25. int main()
  26. {
  27.     citire();
  28.     int i,j,p=0,ok=0;
  29.     cout<<"nr muchii: "<<m;
  30.     cout<<endl<<"grade izolate: ";
  31.     for(i=1;i<=n;i++)
  32.         if(gr(i)==0)p++;
  33.     cout<<p;
  34.     cout<<endl<<"noduri grad par: ";
  35.     for(i=1;i<=n;i++)
  36.         if(gr(i)%2==0) cout<<i<<" ";
  37.     for(i=1;i<=n;i++)
  38.         if(gr(i)!=n-1)ok=1;
  39.     if(ok==0)cout<<endl<<"graful este complet.";
  40.     else cout<<endl<<"graful nu este complet.";
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement