tonibiro

ASD lab10 prob2

Dec 19th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. void DF(int a[][50], int n, int col[], int c, int s)
  6. {
  7.     col[s] = c;
  8.     for(int i = 0; i < n; ++i)
  9.         if(a[s][i] == 1 && col[i] == 0)
  10.             DF(a, n, col, c, i);
  11. }
  12.  
  13. void cit_date(int a[][50], int &n)
  14. {
  15.     ifstream fin("tabel.txt");
  16.  
  17.     int x;
  18.     n = 0;
  19.     fin >> x;
  20.  
  21.  
  22.     for(int i = 0; i < x; ++i)
  23.     {
  24.         int y, z;
  25.         fin >> y >> z;
  26.         if(n < z)
  27.             n = z;
  28.         if(n < y)
  29.             n = y;
  30.         a[y][z] = a[z][y] = 1;
  31.     }
  32.  
  33.  
  34.     fin.close();
  35. }
  36.  
  37.  
  38.  
  39. int main()
  40. {
  41.     int n, a[][50] = {};
  42.     cit_date(a, n);
  43.  
  44.     int col[50] = {};
  45.     int i = 1;
  46.  
  47.     for(int j = 0; j < n; ++j)
  48.     {
  49.         if(col[j] == 0)
  50.         {
  51.             DF(a, n, col, i, j);
  52.             ++i;
  53.         }
  54.     }
  55.     cout << "nr c conexe: " << i;
  56.     return 0;
  57. }
Add Comment
Please, Sign In to add comment