Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define pb(a) push_back(a)
  4. #define mp(a,g) make_pair(a,g)
  5. const int MAX = 10005;
  6. int par[MAX] = {0},child[MAX]={0},low[MAX] = {0},tym[MAX]={0};
  7. bool visit[MAX]={0},isCut={0};
  8. static int t=0;
  9. stack <pair <int,int> > bc;
  10. vector <int> a[MAX];
  11. int odd=0,even=0;
  12. void BCdfs(int s){
  13. visit[s] = true;
  14. low[s]=tym[s]=t++;
  15. for(int i=0;i<a[s].size();i++){
  16. int v = a[s][i];
  17. if(!visit[v]){
  18. par[v] = s;
  19. child[s]++;
  20. bc.push(mp(s,v));
  21. BCdfs(v);
  22.  
  23. low[s] = min(low[s],low[v]);
  24. if((tym[s]==1 and child[s]>1)||( low[v]>=tym[s])){
  25. set<int> nodes;
  26. while(bc.top().first !=s || bc.top().second !=v){
  27. nodes.insert(bc.top().first);
  28. nodes.insert(bc.top().second);
  29. bc.pop();
  30. }
  31. nodes.insert(bc.top().first);
  32. nodes.insert(bc.top().second);
  33. bc.pop();
  34. if(nodes.size()!=0 and nodes.size()&1)odd++;
  35. else even++;
  36. }
  37. }
  38. else if(v!=par[s] && tym[v]<low[s]){
  39. low[s] = min(low[s],tym[v]);
  40. bc.push(mp(s,v));
  41. }
  42. }
  43. }
  44. int main(){
  45. int n,m,x,y;cin>>n>>m;
  46. while(m--){
  47. cin>>x>>y;
  48. a[x+1].pb(y+1);
  49. a[y+1].pb(x+1);
  50. }
  51. par[1] = -1;
  52. for(int i=1;i<=n;i++){
  53. if(!visit[i])
  54. BCdfs(i);
  55. }
  56. set <int> nodes;
  57. while(!bc.empty()){
  58. cout<<bc.top().first<<" "<<bc.top().second<<"\n";
  59. nodes.insert(bc.top().first);
  60. nodes.insert(bc.top().second);
  61. bc.pop();
  62. }
  63.  
  64. if(nodes.size()!=0 and nodes.size()&1)odd++;
  65. else if(nodes.size()!=0 ) even++;
  66.  
  67. cout<<odd<<" "<<even;
  68.  
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement