标签:ssi desc limit arch getc front body nbsp point
Time Limit: 1000MS | Memory Limit: 10000K | |
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<cstdio> #include<cstring> #include<algorithm> #define N 101 using namespace std; int n,id,tot; int dfn[N],low[N]; bool cutpoint[N]; int front[N],to[N*N],nxt[N*N]; void add(int u,int v) { to[++tot]=v; nxt[tot]=front[u]; front[u]=tot; to[++tot]=u; nxt[tot]=front[v]; front[v]=tot; } void tarjan(int u,int pre) { dfn[u]=low[u]=++id; int sum=0; bool tmp=false; for(int i=front[u];i;i=nxt[i]) { if(i==(pre^1)) continue; if(!dfn[to[i]]) { sum++; tarjan(to[i],i); low[u]=min(low[u],low[to[i]]); if(low[to[i]]>=dfn[u]) tmp=true; } else low[u]=min(low[u],dfn[to[i]]); } if(!pre) { if(sum>1) cutpoint[u]=true; } else if(tmp) cutpoint[u]=true; } void clear() { id=0; tot=1; memset(dfn,0,sizeof(dfn)); memset(low,0,sizeof(low)); memset(front,0,sizeof(front)); memset(cutpoint,0,sizeof(cutpoint)); } int main() { int x,y,ans; char c; while(scanf("%d",&n) && n) { clear(); while(scanf("%d",&x) && x) { while((c=getchar())!=‘\n‘) { scanf("%d",&y); add(x,y); } } tarjan(1,0); ans=0; for(int i=1;i<=n;i++) if(cutpoint[i]) ans++; printf("%d\n",ans); } }
标签:ssi desc limit arch getc front body nbsp point
原文地址:http://www.cnblogs.com/TheRoadToTheGold/p/6920547.html