Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- void DF(int a[][50], int n, int col[], int c, int s)
- {
- col[s] = c;
- for(int i = 0; i < n; ++i)
- if(a[s][i] == 1 && col[i] == 0)
- DF(a, n, col, c, i);
- }
- void cit_date(int a[][50], int &n)
- {
- ifstream fin("tabel.txt");
- int x;
- n = 0;
- fin >> x;
- for(int i = 0; i < x; ++i)
- {
- int y, z;
- fin >> y >> z;
- if(n < z)
- n = z;
- if(n < y)
- n = y;
- a[y][z] = a[z][y] = 1;
- }
- fin.close();
- }
- int main()
- {
- int n, a[][50] = {};
- cit_date(a, n);
- int col[50] = {};
- int i = 1;
- for(int j = 0; j < n; ++j)
- {
- if(col[j] == 0)
- {
- DF(a, n, col, i, j);
- ++i;
- }
- }
- cout << "nr c conexe: " << i;
- return 0;
- }
Add Comment
Please, Sign In to add comment