标签:
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 10286 | Accepted: 4775 |
Description
Input
Output
Sample Input
5 5 1 2 3 4 0 6 2 1 3 5 4 6 2 0 0
Sample Output
1 2
Hint
Source
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<set>
#include<map>
using namespace std;
int n,mp[105][105];
int Dfs[105],low[105],top,cnt[105],root,ans;
bool isstack[105];
void tarjan(int u)
{
Dfs[u]=low[u]=++top;
isstack[u]=true;
for(int i=1;i<=n;i++)
{
if(mp[u][i])
{
if(!Dfs[i])
{
tarjan(i);
low[u]=min(low[u],low[i]);
if(low[i]>=Dfs[u]&&u!=1)
{
cnt[u]++;
}
else if(u==1)
{
root++;
}
}
else if(isstack[i])
{
low[u]=min(low[u],Dfs[i]);
}
}
}
}
int main()
{
int y,x;
while(scanf("%d",&n)!=EOF)
{
if(n==0)
break;
ans=0;
memset(low,0,sizeof(low));
memset(Dfs,0,sizeof(Dfs));
memset(isstack,0,sizeof(isstack));
memset(cnt,0,sizeof(cnt));
memset(mp,0,sizeof(mp));
root=0;
while(scanf("%d",&x))
{
if(x==0)
break;
while(getchar()!=‘\n‘)
{
scanf("%d",&y);
mp[x][y]=1;
mp[y][x]=1;
}
}
tarjan(1);
if(root>1)
ans++;
for(int i=2;i<=n;i++)
{
if(cnt[i])
ans++;
}
printf("%d\n",ans);
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/a972290869/p/4435391.html