POJ1144

来源:互联网 发布:使用excel制作软件 编辑:程序博客网 时间:2024/06/05 02:25

求割点

# include <cstdio># include <cstdlib># include <cctype># include <cmath># include <ctime># include <cstring># include <string># include <iostream># include <algorithm>using namespace std;struct P{int to;int next;};P a[20005];int n,first[101],tot,root=1;int low[101],num[101],flag,index;void f(int i,int j){tot++;a[tot].next=first[i];a[tot].to=j;first[i]=tot;}void dfs(int cur,int father){int child=0,u,flag1=0;index++;low[cur]=index;num[cur]=index;u=first[cur];while(u!=0){if(num[a[u].to]==0){child++;dfs(a[u].to,cur);low[cur]=min(low[cur],low[a[u].to]);if(cur!=root && low[a[u].to]>=num[cur]) flag1=1;if(cur==root && child==2) flag1=1;}else if(a[u].to!=father) low[cur]=min(low[cur],num[a[u].to]);u=a[u].next;}if(flag1==1)    flag++;return ;}int main(){//freopen("1.in","r",stdin);//freopen("1.out","w",stdout);int end,i,j;scanf("%d",&end);do{n=end;tot=0;flag=0;index=0;fill(low,low+101,0);fill(num,num+101,0);fill(first,first+101,0);while(scanf("%d",&i)&&i!=0){    while(getchar()!='\n')    {    scanf("%d",&j);    f(i,j);    f(j,i);    }    }    dfs(1,1);    cout<<flag<<endl;}while(scanf("%d",&end)&&end!=0);return 0;}


0 0