#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
#define MAXN 110
#define min(a,b) ( (a)<(b)?(a):(b) )
vector<int> map[MAXN];
int n, cnt;
bool visite[MAXN], flag[MAXN];
int rank[MAXN], low[MAXN];
bool input()
{
for( int i= 0; i<= MAXN; ++i )
map[i].clear();
memset( visite, false, sizeof(visite) );
memset( flag, false, sizeof(flag) );
memset( rank, 0, sizeof(flag) );
memset( low, 0, sizeof(low) );
cnt= 0;
scanf("%d",&n );
if( n== 0 ) return false;
int t;
while( scanf("%d",&t), t!= 0 )
{
char ch;
while( ( ch= getchar() )!= '\n' )
{
int k;
scanf("%d",&k );
map[t].push_back(k), map[k].push_back(t);
}
}
return true;
}
void dfs( int k )
{
++cnt;
rank[k]= cnt, low[k]= cnt, visite[k]= true;
int num= 0;
for( size_t i= 0; i< map[k].size(); ++i )
{
if( !visite[ map[k][i] ] )
{
num++;
dfs( map[k][i] );
low[k]= min( low[k], low[ map[k][i] ] );
if( k!= 1 && low[ map[k][i] ]== rank[k] ) flag[k]= true;
if( k== 1 && num> 1 ) flag[k]= true;
}
else if( k!= map[k][i] )
low[k]= min( low[k], rank[ map[k][i] ] );
}
}
int main()
{
while( input() )
{
dfs(1);
int num= 0;
for( int i= 1; i<= n; ++i )
if( flag[i] ) num++;
printf("%d\n", num );
}
return 0;
}
posted on 2008-12-24 12:11
Darren 阅读(337)
评论(0) 编辑 收藏 引用