Tarjan算法求解割点

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std; const int maxn=;//有多少个结点
vector<int>G[maxn];
int visited[maxn];//标记该节点有没有访问过
int node;//顶点数目
int tmpdfn;//dfs过程中记录当前的深度优先搜索序数
int dfn[maxn];//记录每个顶点的深度优先搜索序数
int low[maxn];//每个顶点的low值,根据该值来判断是否是关节点
int son;//根结点的有多少个孩子,如果大于等于2,则根结点为关节点
int subnets[maxn];//记录每个结点(去掉该结点后)的连通分量的个数 void init()
{
for(int i=;i<maxn;i++) G[i].clear();
low[]=dfn[]=;
tmpdfn=;son=;
memset(visited,,sizeof(visited));
visited[]=;
memset(subnets,,sizeof(subnets));
} void dfs(int u)
{
for(int i=;i<G[u].size();i++)
{
int v=G[u][i];
if(!visited[v])
{
visited[v]=;
tmpdfn++; dfn[v]=low[v]=tmpdfn;
dfs(v);
low[u]=min(low[u],low[v]);
if(low[v]>=dfn[u])
{
if(u!=) subnets[u]++;
if(u==) son++;
}
}
else low[u]=min(low[u],dfn[v]);
}
} int main()
{
int u,v;
int number=;
while()
{
node=;
scanf("%d",&u);
if(u==) break;
scanf("%d",&v); if(u>node) node=u;
if(v>node) node=v; //初始化
init(); //无向图
G[u].push_back(v);
G[v].push_back(u); while()
{
scanf("%d",&u);
if(u==) break;
scanf("%d",&v); if(u>node) node=u;
if(v>node) node=v; //无向图
G[u].push_back(v);
G[v].push_back(u);
}
if(number>) printf("\n");
printf("Network #%d\n",number);
number++;
dfs();
if(son>) subnets[]=son-;
int Find=;
for(int i=;i<=node;i++)
if(subnets[i])
{
Find=;
printf(" SPF node %d leaves %d subnets\n",i,subnets[i]+);
}
if(!Find) printf(" No SPF nodes\n");
} return ;
}

ZOJ 1119 SPF的更多相关文章

  1. zoj 1119 /poj 1523 SPF

    题目描述:考虑图8.9中的两个网络,假定网络中的数据只在有线路直接连接的2个结点之间以点对点的方式传输.一个结点出现故障,比如图(a)所示的网络中结点3出现故障,将会阻止其他某些结点之间的通信.结点1 ...

  2. zoj 1119 / poj 1523 SPF (典型例题 求割点 Tarjan 算法)

    poj : http://poj.org/problem?id=1523 如果无向图中一个点 u 为割点 则u 或者是具有两个及以上子女的深度优先生成树的根,或者虽然不是一个根,但是它有一个子女 w, ...

  3. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  4. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  5. ZOJ题目分类

    ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...

  6. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  7. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  8. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  9. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

随机推荐

  1. 手动安装VS code 插件

    现在安装包: 通过修改下面的地址参数:https://${publisher}.gallery.vsassets.io/_apis/public/gallery/publisher/${publish ...

  2. Log4J1升级Log4J2

    近期,碰到需要将项目中的Log4J1升级到Log4J2,现进行下总结.交代下技术背景:web项目,基于Java + Maven 1. 依赖 <dependency> <groupId ...

  3. md5证书在window2012不能访问

    之前在window 2008使用makecert的产生的证书,部署到window 2012后,发现只有IE能访问,但是Firefox和chrome都不行.Firefox可以使用about:config ...

  4. django urls.py更改遇到问题

    Q:TypeError: view must be a callable or a list/tuple in the case of include() A:django 1.10版本改了写法了.首 ...

  5. Users is not mapped(Hibernate实体类采用注解)

    今天做简单的登陆验证web应用时,用HQL语句查询数据表时 总是出现Users is not mapped [from Users u where u.username=? and u.passwor ...

  6. ZeroMQ中PUB-SUB模式测试

    因为公司有需求,对程序模块之间通信效率有较高的需求.之前公司用的通信组件是ActiveMQ,根据网上公布的测试结果显示其效率比较低, 后来考虑准备在新的项目中开始使用ZeroMQ.看了几天发现用起来比 ...

  7. NYIST OJ 题目42 一笔画问题

    水题.无向图欧拉通路的判定.用并查集判定是不是连通图! #include<cstdio> #include<cstring> #include<cmath> #in ...

  8. linux搭建phantomjs+webdriver+testng+ant自动化工程

    因为项目的原因,需要将脚本在linux环境无浏览器化去跑,那么原有的在windows系统下有浏览器化的自动化脚本场景就不适用了,这里给出linux系统下搭建phantomjs+webdriver+te ...

  9. 一行一行分析JQ源码学习笔记-04

    jquery添加方法和属性 jquery.fn=jquery.prototype ={ jquery版本 } construtor  指向修正 js源码中 fun  aaa(){} 会自动生成一句   ...

  10. 4、Spring+MyBatis增删改查

    0.oracle数据库脚本 create table userinfo (id ), name ), password telephone ), isadmin )); --4.2 用户表序列 cre ...