Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream fin("graf.txt");
  7.  
  8. int a[100][100];
  9. int main()
  10. {
  11.     int i, j, m, n, x, y, d, nod, grad, izolate = 0, ok = 0, p;
  12.     fin >> n >> m;
  13.  
  14.     for(i=1; i<=m; i++){
  15.         fin >> x >> y;
  16.         a[x][y] = a[y][x] = 1;
  17.     }
  18.  
  19.     for(i=1; i<=n; i++){
  20.         for(j=1; j<=n; j++)
  21.             cout<<a[i][j];
  22.         cout << endl;
  23.     }
  24.  
  25.     cin >> nod;
  26.  
  27.     d = 0;
  28.     for(i=1; i<=n; i++){
  29.         if(a[i][nod] == 1){
  30.             d++;
  31.             cout << i << " ";
  32.         }
  33.     }
  34.     cout << endl;
  35.  
  36.     for(i=1; i<=n; i++){
  37.         grad = 0;
  38.         for(j=1; j<=n; j++)
  39.             if(a[i][j] == 1) grad++;
  40.         cout<< i << " are gradul "<< grad << endl;
  41.         if(grad == 0) izolate++;
  42.     }
  43.     for(i=1; i<=n && ok == 0; i++){
  44.         grad = 0;
  45.         for(j=1; j<=n; j++)
  46.             if(a[i][j] == 1) grad++;
  47.         if(grad!=n-1) ok++;
  48.     }
  49.  
  50.     if(ok == 0) cout << "Graful este complet.\n";
  51.     else cout << "Graful nu este complet.\n";
  52.     cout << "Sunt " << izolate << " varfuri izolate.\n";
  53.     cout << "Trebuie adaugate minim " << izolate << " muchii.\n";
  54.  
  55.     cin >> p;
  56.     for(i=1; i<=p; i++)
  57.         // ceva cod aici
  58.  
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement