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

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

查看所有标签

猜你喜欢:

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

Ruby on Rails敏捷开发最佳实践

Ruby on Rails敏捷开发最佳实践

李刚 / 电子工业出版社 / 2008-4 / 79.80元

《Ruby on Rails敏捷开发最佳实践》适用于正在使用Ruby On Rails进行应用开发的开发人员、渴望了解Ruby On Rails框架的开发人员,尤其适合有初步的Java EE开发经验,想从Java EE平台过渡到Ruby On Rails开发平台的开发者。 Ruby On Rails框架一经推出,立即引起B/S结构应用开发领域革命性的变化:开发者无需理会架构,只需要按Rail......一起来看看 《Ruby on Rails敏捷开发最佳实践》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

MD5 加密
MD5 加密

MD5 加密工具