Advertisement
LinKin

Biconnected Component

Dec 5th, 2013
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. /*
  2.  * Algorithm: Finding Biconnected Component
  3.  * Complexity: O( V+E )
  4.  * Note : Can be used for articulation/ bridge finding by using isArt etc
  5.  */
  6.  
  7. long N; vector<long> edge[MAX+7];
  8. bool vi[MAX+7],isArt[MAX+7];
  9. long low[MAX+7],ind[MAX+7],I;// I for ind countin
  10. long par[MAX+7],nChild[MAX+7];
  11. stack< pair<long,long> > stk;
  12. void Dfs( long u ){
  13.     vi[u] = true; ind[u] = ++I; low[u] = I;
  14.     nChild[u] = 0; isArt[u] = false;
  15.     long i;
  16.     for( i=0;i<edge[u].size();i++){
  17.         long v = edge[u][i];
  18.         if( !vi[v]){
  19.             par[v] = u; nChild[u]++; stk.push( MP( u,v ) ); Dfs( v);
  20.             if( low[v] >= ind[u] ){ // Find new Component
  21.                 while( stk.top() != MP(u,v) ) stk.pop(); // stk.top() is an edge
  22.                 stk.pop();
  23.             }
  24.             low[u] = min( low[u],low[v]);
  25.         } else if( par[u] != v ){
  26.             if( ind[v]<ind[u] ) stk.push( MP( u,v ) );
  27.             low[u] = min( low[u],ind[v]);
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement