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();
    }
}

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

查看所有标签

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

计算机科学导论

计算机科学导论

Behrouz A.Forouzan / 刘艺 / 机械工业出版社 / 2009-1 / 30.00元

本书是大学计算机相关专业的基础课教材,涉及到计算机科学的各个方面。本书着重讲解基本概念而不是数学模型和技术细节,通过大量的图表和演示范例讲解计算机科学的基础知识;每章后面的关键术语、小结和练习有助于读者掌握和复习知识要点。 本书既适合当作大专院校的计算机基础课教材,也可作为一般的计算机基础入门读物。一起来看看 《计算机科学导论》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

SHA 加密
SHA 加密

SHA 加密工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具