内容简介:题目链接:思路:割点板子,此题数据读入有些小毒瘤。
题目链接: 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();
}
}
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
数据结构与算法分析
[美]Mark Allen Weiss / 张怀勇 / 人民邮电出版社 / 2007年 / 49.00元
《数据结构与算法分析:C++描述(第3版)》是数据结构和算法分析的经典教材,书中使用主流的程序设计语言C++作为具体的实现语言。书的内容包括表、栈、队列、树、散列表、优先队列、排序、不相交集算法、图论算法、算法分析、算法设计、摊还分析、查找树算法、k-d树和配对堆等。《数据结构与算法分析:C++描述(第3版)》适合作为计算机相关专业本科生的数据结构课程和研究生算法分析课程的教材。本科生的数据结构课......一起来看看 《数据结构与算法分析》 这本书的介绍吧!