Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author : unlucky_13
- Problem_link :
- Category :
- Algorithm_Used :
- */
- #include<cstdio>
- #include<sstream>
- #include<cstdlib>
- #include<cctype>
- #include<cmath>
- #include<algorithm>
- #include<set>
- #include<queue>
- #include<stack>
- #include<list>
- #include<iostream>
- #include<fstream>
- #include<numeric>
- #include<string>
- #include<vector>
- #include<cstring>
- #include<map>
- #include<iterator>
- #define LL long long int
- //const long long int inf = 2147483647 ;
- //const int minx=;
- const int maxn=100;
- using namespace std;
- vector<int>to[maxn];
- int dfsn[maxn],low[maxn],art[maxn],tim,n,ans,child_of_root;
- void reset(){
- for(int i=0;i<=n;i++) to[i].clear();
- ans = tim=child_of_root=0;
- memset(dfsn,-1,sizeof(dfsn)) ;
- memset(low,0,sizeof(low)) ;
- memset(art,0,sizeof(art)) ;
- }
- void DFS(int u,int p)
- {
- dfsn[u]=low[u]=tim++;
- int ch = 0 ;
- for(int i=0;i<(int)to[u].size();i++)
- {
- int v=to[u][i];
- if(dfsn[v]==-1){
- ch++ ;
- DFS(v,u);
- low[u]=min(low[u],low[v]);
- if(dfsn[u]>0 && low[v]>=dfsn[u]) art[u]=1 ;
- }
- else if(v!=p)low[u]=min(low[u],dfsn[v]);
- }
- if(dfsn[u]==0 && ch>1) art[u]=1 ;
- }
- int main() {
- freopen("C:\\Users\\Mazhar\\Desktop\\Text_Files\\in.txt", "r", stdin);
- int m,x;
- string line ;
- while(scanf("%d\n",&n) && n){
- reset() ;
- while(1){
- getline(cin,line) ;
- istringstream s(line) ;
- s>>m ;
- // cout<<m<<endl ;
- if(m==0) break ;
- while(s>>x){
- // cout<<x<<endl ;
- to[m].push_back(x) ;
- to[x].push_back(m) ;
- }
- }
- // cout<<"--------------------"<<endl ;
- for(int i=1;i<=n;i++){
- if(dfsn[i]==-1) DFS(i,-1);
- }
- ans = 0 ;
- for(int i=1;i<=n;i++){
- ans+=art[i] ;
- }
- cout<<ans<<endl ;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment