the_art_of_war

Untitled

May 22nd, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. bool used[MAXN];
  2. int tin[MAXN],fup[MAXN],timer;
  3. stack<pii> st;
  4. vector<vector<pii> > com;
  5. void dfs(int v,int p){
  6. used[v] = 1;
  7. fup[v] = timer;
  8. tin[v] = timer++;
  9. int child = 0;
  10. for(int to:g[v]){
  11. if(to==p)
  12. continue;
  13. if(used[to]){
  14. if(tin[to] < fup[v]){
  15. fup[v] = tin[to];
  16. st.push({v,to});
  17. }
  18.  
  19. } else{
  20. child++;
  21. st.push({v,to});
  22. dfs(to,v);
  23. fup[v] = min(fup[v],fup[to]);
  24. if(p==-1 && child>1){
  25. // cout << "ver " << v <<" "<<to<<endl;
  26. vector<pii> temp;
  27. while(st.top()!=make_pair(v,to)){
  28. temp.pb(st.top());
  29. st.pop();
  30. }
  31. temp.pb(st.top());
  32. st.pop();
  33.  
  34. com.pb(temp);
  35. }
  36. if(p!=-1 && fup[to]>=tin[v]){
  37. // cout << "ver " << v <<" "<<to<<endl;
  38. vector<pii> temp;
  39. while(st.top()!=make_pair(v,to)){
  40. temp.pb(st.top());
  41. st.pop();
  42. }
  43. temp.pb(st.top());
  44. st.pop();
  45.  
  46. com.pb(temp);
  47. }
  48.  
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment