ZOJ 1119 SPF
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的更多相关文章
- zoj 1119 /poj 1523 SPF
题目描述:考虑图8.9中的两个网络,假定网络中的数据只在有线路直接连接的2个结点之间以点对点的方式传输.一个结点出现故障,比如图(a)所示的网络中结点3出现故障,将会阻止其他某些结点之间的通信.结点1 ...
- zoj 1119 / poj 1523 SPF (典型例题 求割点 Tarjan 算法)
poj : http://poj.org/problem?id=1523 如果无向图中一个点 u 为割点 则u 或者是具有两个及以上子女的深度优先生成树的根,或者虽然不是一个根,但是它有一个子女 w, ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- ZOJ题目分类
ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
随机推荐
- jquery获取radio的值
Html代码是 <label><input type="radio" name="proofing" value="1"& ...
- CNN计算过程
- 用SqlBulkCopy批量插入数据到SqlServer数据库表中
首先创建一个数据库连接类:SQLHelper using System; using System.Collections.Generic; using System.Linq; using Syst ...
- redhat nginx 启动脚本
#!/bin/sh # # nginx - this script starts and stops the nginx daemin # # chkconfig: - 85 15 # descrip ...
- 共享AFHTTPSessionManager 单例好处浅析
很多时候,AFNetworking都是目前iOS开发者网络库中的不二选择.Github上2W+的star数足见其流行程度.而从iOS7.0开始,苹果推出了新的网络库继承者NSURLSession后 ...
- 完全删除Postgresql
First: If your install isn't already damaged, you can drop unwanted PostgreSQL servers ("cluste ...
- Oracle截取某字段前后字符串
创建测试表及数据 1 2 3 4 5 6 7 8 9 create table test (name varchar2(10)); insert into test values ('2-15') ...
- flume-hdfs sinks报错
flume使用hdfs sinks时候报错:org.apache.flume.EventDeliveryException: java.lang.NullPointerException: Expec ...
- HttpWebRequest的简单使用
新建新的空网站和一个default.aspx页面测试,实验例子: using System; using System.Collections.Generic; using System.IO; us ...
- ckplayer 项目实战
<div class="control-group" id="videoDiv" style="display: none;"> ...