unlucky_13

uva_315_Network

May 22nd, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.10 KB | None | 0 0
  1. /*
  2.  Author                             :     unlucky_13
  3.  Problem_link                       :
  4.  Category                           :
  5.  Algorithm_Used                     :
  6.  */
  7.  
  8. #include<cstdio>
  9. #include<sstream>
  10. #include<cstdlib>
  11. #include<cctype>
  12. #include<cmath>
  13. #include<algorithm>
  14. #include<set>
  15. #include<queue>
  16. #include<stack>
  17. #include<list>
  18. #include<iostream>
  19. #include<fstream>
  20. #include<numeric>
  21. #include<string>
  22. #include<vector>
  23. #include<cstring>
  24. #include<map>
  25. #include<iterator>
  26. #define LL long long int
  27. //const long long int inf = 2147483647 ;
  28. //const int minx=;
  29. const int maxn=100;
  30.  
  31. using namespace std;
  32. vector<int>to[maxn];
  33. int dfsn[maxn],low[maxn],art[maxn],tim,n,ans,child_of_root;
  34. void reset(){
  35.         for(int i=0;i<=n;i++) to[i].clear();
  36.         ans = tim=child_of_root=0;
  37.         memset(dfsn,-1,sizeof(dfsn)) ;
  38.         memset(low,0,sizeof(low)) ;
  39.         memset(art,0,sizeof(art)) ;
  40.    
  41. }
  42. void DFS(int u,int p)
  43. {
  44.    
  45.     dfsn[u]=low[u]=tim++;
  46.     int ch = 0 ;
  47.     for(int i=0;i<(int)to[u].size();i++)
  48.     {
  49.         int v=to[u][i];
  50.         if(dfsn[v]==-1){
  51.             ch++ ;
  52.             DFS(v,u);
  53.             low[u]=min(low[u],low[v]);
  54.             if(dfsn[u]>0 && low[v]>=dfsn[u]) art[u]=1 ;
  55.  
  56.         }
  57.        
  58.         else if(v!=p)low[u]=min(low[u],dfsn[v]);
  59.  
  60.     }
  61.     if(dfsn[u]==0 && ch>1) art[u]=1 ;
  62.    
  63. }
  64.  
  65. int main() {
  66.  
  67.     freopen("C:\\Users\\Mazhar\\Desktop\\Text_Files\\in.txt", "r", stdin);
  68.     int m,x;
  69.     string line ;
  70.     while(scanf("%d\n",&n) && n){
  71.         reset() ;
  72.         while(1){
  73.             getline(cin,line) ;
  74.             istringstream s(line) ;
  75.             s>>m ;
  76.            // cout<<m<<endl ;
  77.             if(m==0) break ;
  78.             while(s>>x){
  79.               //  cout<<x<<endl ;
  80.                 to[m].push_back(x) ;
  81.                 to[x].push_back(m) ;
  82.             }
  83.         }
  84.       // cout<<"--------------------"<<endl ;
  85.        
  86.         for(int i=1;i<=n;i++){
  87.             if(dfsn[i]==-1)   DFS(i,-1);
  88.         }
  89.         ans = 0 ;
  90.         for(int i=1;i<=n;i++){
  91.             ans+=art[i] ;
  92.         }
  93.         cout<<ans<<endl ;
  94.        
  95.        
  96.        
  97.        
  98.        
  99.        
  100.     }
  101.    
  102.  
  103.     return 0;
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment