Guest User

muie badii

a guest
Jan 14th, 2020
78
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <fstream>
  2.  
  3. using namespace std;
  4.  
  5. bool a[105][105];
  6. int n, viz[105];
  7. ifstream fin("componenteconexe.in");
  8. ofstream fout("componenteconexe.out");
  9.  
  10. void citire()
  11. {
  12. int x,y;
  13. fin>>n;
  14.  
  15. while(fin>>x>>y)
  16. a[x][y]=a[y][x]=1;
  17.  
  18.  
  19. }
  20. void DFS(int x,int k)
  21. {
  22. viz[x]=k;
  23. for(int i=1; i<=n ; i++)
  24. if (a[i][x]&&!viz[i])
  25. DFS(i,k);
  26. }
  27. void afisare(int k)
  28. {
  29. fout<<k<<'\n';
  30. for(int i=1; i<=k ; i++)
  31. {
  32. for(int j=1; j<=n; j++)
  33. if (viz[j]==i)
  34. fout<<j<<" ";
  35. fout<<'\n';
  36. }
  37. }
  38.  
  39. int main()
  40. {
  41. int k=0;
  42. citire();
  43. for(int i=1; i<=n; i++)
  44. if(!viz[i])
  45. {
  46. k++;
  47. DFS(i,k);
  48. }
  49. afisare(k);
  50.  
  51. return 0;
  52. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×