poj 1144 求割点

赤裸裸的求割点的题 模板
zsd:
    while((c=getchar())!='\n')
            {
                scanf("%d",&y);
                edge[x][y]=edge[y][x]=1;
            }
getchar()的小用法;
输入类似数据
5 1 2 3 4
 

 


#include<iostream> #include<cstring> using namespace std; int dfn[111],low[111]; int edge[111][111]; int b[111]; int sum; int visited[111]; int n; int son; int tm; int min(int x,int y) { if(x<y) return x; return y; } void dfs(int u) { for(int v=1;v<=n;v++) { if(edge[u][v]) { if(!visited[v]) { visited[v]=1; tm++;dfn[v]=low[v]=tm; dfs(v); low[u]=min(low[u],low[v]); if(low[v]>=dfn[u]) { if(u!=1&&!b[u]) { b[u]=1; sum++; } if(u==1) son++; } } else low[u]=min(low[u],dfn[v]); } } } int main() { int x,i,y; char c; //char a[1111]; while(scanf("%d",&n)!=EOF) { if(n==0) break; memset(edge,0,sizeof(edge)); while(scanf("%d",&x)&&x) { while((c=getchar())!='\n') { scanf("%d",&y); edge[x][y]=edge[y][x]=1; } } memset(visited,0,sizeof(visited)); low[1]=dfn[1]=1;tm=1;visited[1]=1; son=sum=0; memset(b,0,sizeof(b)); dfs(1); if(son>=2)sum++; printf("%d\n",sum); } return 0; }

 

posted @ 2014-04-30 19:46  _一千零一夜  阅读(126)  评论(0编辑  收藏  举报