poj 1144

题目大意:

无向图求割点

思路:

学习一下点双

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<cmath>
 6 #include<algorithm>
 7 #include<queue>
 8 #include<vector>
 9 #define ll long long
10 #define inf 2139062143
11 #define MAXN 10100
12 using namespace std;
13 inline int read()
14 {
15     int x=0,f=1;char ch=getchar();
16     while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}
17     while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();}
18     return x*f;
19 }
20 int n,res,stp,rts,cnt,fst[MAXN],to[MAXN<<2],nxt[MAXN<<2],dfn[MAXN],low[MAXN],ans[MAXN];
21 void add(int u,int v) {nxt[++cnt]=fst[u],fst[u]=cnt,to[cnt]=v;}
22 void tarjan(int x)
23 {  
24     dfn[x]=low[x]=++stp;
25     for(int i=fst[x];i;i=nxt[i])
26         if(!dfn[to[i]])
27         {
28             tarjan(to[i]);
29             low[x]=min(low[x],low[to[i]]);
30             if(low[to[i]]>=dfn[x]&&x!=1)
31                 if(!ans[x]) ans[x]=1,res++;
32                 else ans[x]=1;
33             else if(x==1) rts++;
34         }
35         else low[x]=min(low[x],dfn[to[i]]);
36 }
37 int main()  
38 {  
39     while(scanf("%d",&n)&&n)
40     {
41         memset(fst,0,sizeof(fst));
42         memset(ans,0,sizeof(ans));
43         memset(dfn,0,sizeof(dfn));
44         res=rts=stp=0;int a,b;
45         while(scanf("%d",&a)&&a)
46             while(getchar()!='\n') {scanf("%d",&b);add(a,b);add(b,a);}
47         tarjan(1);
48         if(rts>1) res++;
49         printf("%d\n",res);
50     }
51 }
View Code

猜你喜欢

转载自www.cnblogs.com/yyc-jack-0920/p/9091874.html
今日推荐