内容简介:题目链接:思路:割点板子,此题数据读入有些小毒瘤。
题目链接: http://poj.org/problem?id=1144
思路:割点板子,此题数据读入有些小毒瘤。
#include <cstdio> #include <cctype> #include <cstring> #include <set> #include <iostream> static const int MAXN=15000; static const int MAXM=505000; struct Edge { int to,nextt; }edge[MAXM]; int n,u,v,num,cnt,ans,head[MAXN],dfn[MAXN],low[MAXN]; std::set<int> s; inline int get_min(int a,int b){return a<b?a:b;} inline void addedge(int u,int v) { edge[++num].to=v; edge[num].nextt=head[u]; head[u]=num; } inline bool check(int u,int fa,int to,int child){return (u==fa&&child>=2)||(u!=fa&&low[to]>=dfn[u])?true:false;} void tarjan(int u,int fa) { dfn[u]=low[u]=++cnt; int child=0; for(int i=head[u];i;i=edge[i].nextt) { int to=edge[i].to; if(!dfn[to]) { tarjan(to,u); low[u]=get_min(low[u],low[to]); if(u==fa) child++; if(check(u,fa,to,child)) s.insert(u); } else low[u]=get_min(low[u],dfn[to]); } } inline void init() { ans=0; cnt=0; s.clear(); memset(low,0,sizeof(low)); memset(dfn,0,sizeof(dfn)); memset(head,0,sizeof(head)); memset(edge,0,sizeof(edge)); } int main() { while(~scanf("%d",&n)&&n) { while(~scanf("%d",&u)&&u) { while(getchar()!='\n') { scanf("%d",&v); addedge(u,v); addedge(v,u); } } for(int i=1;i<=n;i++) if(!dfn[i]) tarjan(i,i); printf("%lu\n",s.size()); init(); } }
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Non-Obvious
Rohit Bhargava / Ideapress Publishing / 2015-3-29 / USD 24.95
What do Disney, Bollywood, and The Batkid teach us about how to create celebrity experiences for our audiences? How can a vending-machine inspire world peace? Can being imperfect make your business mo......一起来看看 《Non-Obvious》 这本书的介绍吧!