Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Algorithm: Finding Biconnected Component
- * Complexity: O( V+E )
- * Note : Can be used for articulation/ bridge finding by using isArt etc
- */
- long N; vector<long> edge[MAX+7];
- bool vi[MAX+7],isArt[MAX+7];
- long low[MAX+7],ind[MAX+7],I;// I for ind countin
- long par[MAX+7],nChild[MAX+7];
- stack< pair<long,long> > stk;
- void Dfs( long u ){
- vi[u] = true; ind[u] = ++I; low[u] = I;
- nChild[u] = 0; isArt[u] = false;
- long i;
- for( i=0;i<edge[u].size();i++){
- long v = edge[u][i];
- if( !vi[v]){
- par[v] = u; nChild[u]++; stk.push( MP( u,v ) ); Dfs( v);
- if( low[v] >= ind[u] ){ // Find new Component
- while( stk.top() != MP(u,v) ) stk.pop(); // stk.top() is an edge
- stk.pop();
- }
- low[u] = min( low[u],low[v]);
- } else if( par[u] != v ){
- if( ind[v]<ind[u] ) stk.push( MP( u,v ) );
- low[u] = min( low[u],ind[v]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement