Advertisement
nicuvlad76

Untitled

Jan 23rd, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define N 30005
  3. using namespace std;
  4. int disc[N], low[N];
  5. vector<int >A[N];
  6. int n, nr,ct;
  7.  
  8. void DFS(int u, int p)
  9. {
  10. disc[u]=low[u]=++nr;
  11. int w;
  12. for(int i=0;i<A[u].size();i++)
  13. {
  14. w=A[u][i];
  15. if(w==p)continue;
  16. if(disc[w])low[u]=min(low[u],disc[w]);
  17. else
  18. {
  19. DFS(w,u);
  20. low[u]=min(low[u],low[w]);
  21. if(low[w]>disc[u])ct++;
  22. }
  23. }
  24. }
  25. void Citire()
  26. {
  27. cin>>n;
  28. int x,y;
  29. for(int i=1;i<=n;i++)
  30. {
  31. cin>>x>>y;
  32. A[x].push_back(y);
  33. A[y].push_back(x);
  34. }
  35. DFS(1,0);
  36. cout<<n-ct;
  37. }
  38. int main()
  39. {
  40. Citire();
  41. return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement