DSA
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.1 KiB

  1. #include <iostream>
  2. #include <map>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <cstdlib>
  6. #include <cstdio>
  7. using namespace std ;
  8. map<pair<int,int>,int> mp ;
  9. int tin[20001] , fup[20001] , timer ;
  10. vector <int> g[20001] , ans ;
  11. bool used[20001] ;
  12. void dfs(int v,int p = -1)
  13. {
  14. used[v] = 1 ;
  15. tin[v]=fup[v]=timer,timer++ ;
  16. for(int i = 0 ; i < g[v].size() ; ++i)
  17. {
  18. int u = g[v][i] ;
  19. if(u==p)
  20. continue ;
  21. if(used[u])
  22. fup[v]=min(fup[v],tin[u]) ;
  23. else
  24. {
  25. dfs(u,v) ;
  26. fup[v] = min(fup[v],fup[u]) ;
  27. if(tin[v]<fup[u])
  28. {
  29. pair<int,int>pr ;
  30. pr.first = v , pr.second = u ;
  31. ans.push_back(mp[pr]) ;
  32. }
  33. }
  34. }
  35. }
  36. int main()
  37. {
  38. int n , m ;
  39. cin >> n >> m ;
  40. for(int i = 0 ; i < m ; ++i)
  41. {
  42. pair<int,int>pr ;
  43. cin >> pr.first >> pr.second ;
  44. mp[pr] = i+1 ;
  45. pair<int,int>pr1;
  46. pr1.first = pr.second ;
  47. pr1.second = pr.first ;
  48. mp[pr1] = i+1 ;
  49. g[pr.first].push_back(pr.second) ;
  50. g[pr.second].push_back(pr.first) ;
  51. }
  52. for(int i = 0 ; i <= n ; ++i)
  53. {
  54. if(!used[i])
  55. dfs(i) ;
  56. }
  57. cout << ans.size() << '\n' ;
  58. sort(ans.begin(),ans.end()) ;
  59. for(int i = 0 ; i < ans.size() ; ++i)
  60. {
  61. cout << ans[i] << ' ' ;
  62. }
  63. }