SHARE
TWEET

Untitled

a guest Feb 26th, 2020 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. ifstream fin ("bazine.in");
  6. ofstream fout ("bazine.out");
  7.  
  8.  
  9. int n, viz[101], a[101][101], m, X, NrC;
  10.  
  11. void citire()
  12. {
  13.     int x , y;
  14.     fin >> n >> m;
  15.     while (fin >> x >> y)
  16.     {
  17.         a[x][y]=a[y][x]=1;
  18.     }
  19. }
  20.  
  21. void Dfs(int nod)
  22. {
  23.     viz[nod]=NrC;
  24.     for (int i=1; i<=n; i++)
  25.     {
  26.         if (a[nod][i]==1 and !viz[i])
  27.             Dfs(i);
  28.     }
  29.  
  30. }
  31. void compcon()
  32. {
  33.     for (int i=1; i<=n; i++)
  34.     {
  35.         if (viz[i]==0)
  36.         {
  37.             NrC++;
  38.             Dfs(i);
  39.         }
  40.     }
  41.     fout << NrC;
  42. }
  43.  
  44. int main()
  45. {
  46.     citire();
  47.     compcon();
  48.     return 0;
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top