码迷,mamicode.com
首页 > Web开发 > 详细

[poj1144]Network(求割点模板)

时间:2017-10-20 10:11:01      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:getchar   clu   tarjan   poj   pre   cto   ace   col   ack   

解题关键:割点模板题,整理模板,未提交。暂时保存。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<vector>
 4 #include<stack>
 5 using namespace std;
 6 #define N 1010
 7 int n,m,ans,pd,son,cut[N],low[N],dfn[N];
 8 stack<int>s;
 9 const int maxn=1e5+3;
10 struct Edge{
11     int nxt;
12     int to;
13     int w;
14 }e[maxn];
15 int head[maxn],cnt;
16 void add_edge(int u,int v){
17     e[cnt].to=v;
18     e[cnt].nxt=head[u];
19     head[u]=cnt++;
20 }
21 void tarjan(int u){
22     low[u]=dfn[u]=++pd;
23     for(int i=head[u];i!=-1;i=e[i].nxt){
24         int v=e[i].to;
25         if(!dfn[v]){
26             tarjan(v);
27             low[u]=min(low[u],low[v]);
28             if(low[v]>=dfn[u]&&u!=1) cut[u]++;
29             else if(u==1) son++;
30         }
31         else low[u]=min(low[u],dfn[v]);
32     }
33 }
34 int main(){
35     while(scanf("%d",&n)==1&&n){
36         int u,v;
37         memset(dfn,0,sizeof dfn);
38         memset(cut,0,sizeof cut);
39         memset(head,-1,sizeof head);
40         pd=ans=son=0;
41         while(scanf("%d",&u)==1&&u){
42             while(getchar()!=\n){
43                 scanf("%d",&v);
44                 add_edge(u,v);
45                 add_edge(v,u);
46             }
47         }
48         tarjan(1);
49         for(int i=1;i<=n;i++) if(cut[i]) ans++;
50         if(son>1) ans++;
51         printf("%d\n",ans);
52     }
53     return 0;
54 }

 

[poj1144]Network(求割点模板)

标签:getchar   clu   tarjan   poj   pre   cto   ace   col   ack   

原文地址:http://www.cnblogs.com/elpsycongroo/p/7697480.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!