POJ 1144 Network

栏目: 编程工具 · 发布时间: 7年前

内容简介:题目链接:思路:割点板子,此题数据读入有些小毒瘤。

题目链接: 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();
    }
}

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

精通CSS与HTML设计模式

精通CSS与HTML设计模式

Michael Bowers / 刘申 朱瑜敏 鲁奇 / 人民邮电出版社 / 2008-9 / 69.00元

本书是一部非常实用的CSS 与HTML(XHTML)解决方案手册。书中包含了350 多种可以立即使用的设计模式(涉及文本、背景、边框、图片、表格、布局等多方面),并介绍了每种模式的原理和使用。每种设计模式、示例和源代码都经过了精心设计,易于实现和使用。通过阅读此书,可大大提高读者在 Web 设计和开发中的效率和创造力。 本书结构清晰,示例丰富,实践性强,适用于所有Web 开发和设计人员......一起来看看 《精通CSS与HTML设计模式》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具