Advertisement
LinKin

Articulation Point

Feb 21st, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<vector>
  4. #include<algorithm>
  5. using namespace std;
  6.  
  7. #define MAX_V 107
  8.  
  9. vector<long> Edge[ MAX_V+7];
  10. long nVertex;
  11.  
  12. bool Visit[ MAX_V+7];
  13. long Ind[ MAX_V+7],I;// I for Ind countin
  14. long nChild[ MAX_V+7];
  15. bool IsArt[ MAX_V+7];
  16. long Low[ MAX_V+7];
  17. long p[ MAX_V+7];
  18.  
  19.  
  20. void Dfs( long u)
  21. {
  22.     // init
  23.     Visit[u] =true;
  24.     Ind[u] =++I;
  25.     nChild[u] =0;
  26.     IsArt[u] =false;
  27.     Low[u] =I;
  28.     long i;
  29.     for( i=0;i<Edge[u].size();i++){
  30.         long v =Edge[u][i];
  31.         if( !Visit[v]){
  32.             p[v] =u;
  33.             nChild[u]++;
  34.             Dfs( v);
  35.             // for findin bridge Low[v] > Ind[u]
  36.             if( Low[v] >= Ind[u] && p[u]!=-1) IsArt[u] =true;
  37.             Low[u] =min( Low[u],Low[v]);
  38.         }
  39.         else if( p[u] !=v){
  40.             Low[u] =min( Low[u],Ind[v]);
  41.         }
  42.     }
  43. }
  44.  
  45.  
  46. long Calc( void)
  47. {
  48.     long i;
  49.     memset( &Visit[1],0,sizeof(bool)*nVertex);
  50.     for( i=1;i<=nVertex;i++){
  51.         if( Visit[i]) continue;
  52.         p[i] =-1;
  53.         I =0;
  54.         Dfs( i);
  55.         if( nChild[i]>1) IsArt[i] =true;// special check for root
  56.     };
  57.  
  58.     long Ans =0;
  59.     for( i=1;i<=nVertex;i++){
  60.         if( IsArt[i]) Ans++;
  61.     }
  62.  
  63.     return Ans;
  64. }
  65.  
  66.  
  67. int main( void)
  68. {
  69.     Input();
  70.     long Ans =Calc();
  71.     printf("%ld\n",Ans);
  72.  
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement