Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool used[MAXN];
- int tin[MAXN],fup[MAXN],timer;
- stack<pii> st;
- vector<vector<pii> > com;
- void dfs(int v,int p){
- used[v] = 1;
- fup[v] = timer;
- tin[v] = timer++;
- int child = 0;
- for(int to:g[v]){
- if(to==p)
- continue;
- if(used[to]){
- if(tin[to] < fup[v]){
- fup[v] = tin[to];
- st.push({v,to});
- }
- } else{
- child++;
- st.push({v,to});
- dfs(to,v);
- fup[v] = min(fup[v],fup[to]);
- if(p==-1 && child>1){
- // cout << "ver " << v <<" "<<to<<endl;
- vector<pii> temp;
- while(st.top()!=make_pair(v,to)){
- temp.pb(st.top());
- st.pop();
- }
- temp.pb(st.top());
- st.pop();
- com.pb(temp);
- }
- if(p!=-1 && fup[to]>=tin[v]){
- // cout << "ver " << v <<" "<<to<<endl;
- vector<pii> temp;
- while(st.top()!=make_pair(v,to)){
- temp.pb(st.top());
- st.pop();
- }
- temp.pb(st.top());
- st.pop();
- com.pb(temp);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment