输入很奇葩,然后是使用链式前向星的时候数组开小了,一直TLE。
#include<stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;
int head[105],cnt,p[105],ans[105],dfs_clock;
struct E{
int to,next;
}edge[10005];
inline void add(int u,int v)
{
edge[cnt].to=v;
edge[cnt].next=head[u];
head[u]=cnt++;
}
int dfs(int u,int fa)
{
int lowu=p[u]=++dfs_clock,child=0;
for(int i=head[u];~i;i=edge[i].next)
{
if(!p[edge[i].to])
{
++child;
int lowv=dfs(edge[i].to,u);
lowu=min(lowu,lowv);
if(lowv>=p[u]) ans[u]=1;
}
else if(p[edge[i].to]<p[u]&&edge[i].to!=fa) lowu=min(lowu,p[edge[i].to]);
}
if(fa<0&&child==1) ans[u]=0;
return lowu;
}
int main()
{
int i,n,x,y;
while(~scanf("%d",&n)&&n)
{
cnt=dfs_clock=0;
memset(head,-1,sizeof(head));
memset(p,0,sizeof(p));
memset(ans,0,sizeof(ans));
while(scanf("%d",&x)&&x)
{
while(getchar()!='\n')
{
scanf("%d",&y);
add(x,y);
add(y,x);
}
}
dfs(1,-1);
for(i=1;i<=n;++i) ans[0]+=ans[i];
printf("%d\n",ans[0]);
}
return 0;
}