Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream fin ("componenteconexe2.in");
  4. ofstream fout ("componenteconexe2.out");
  5. int n , a[105][105] , nrm , nrnod;
  6. bool viz[105];
  7. void DFS(int nod)
  8. {
  9. viz[nod] = true;
  10. nrnod++;
  11. for(int i = 1 ; i <= n ; i++)
  12. if(a[nod][i] == 1)
  13. nrm++;
  14. for(int i = 1 ; i <= n ; i++)
  15. if(viz[i] == 0 && a[nod][i] == 1)
  16. DFS(i);
  17. }
  18. int main()
  19. {
  20. int x , y , s = 0;
  21. fin >> n;
  22. while(fin >> x >> y)
  23. a[x][y] = a[y][x] = 1;
  24. for(int i = 1 ; i <= n ; i++)
  25. if(!viz[i])
  26. {
  27. nrm = nrnod = 0;
  28. DFS(i);
  29. nrm /= 2;
  30. s += (nrm - nrnod + 1);
  31. }
  32. fout << s << "\n";
  33. fin.close();
  34. fout.close();
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement