TZOJ 2018 SPF(连通图割点和分成的连通块)
描述
Consider the two networks shown below. Assuming that data moves around these networks only between directly connected nodes on a peer-to-peer basis, a failure of a single node, 3, in the network on the left would prevent some of the still available nodes from communicating with each other. Nodes 1 and 2 could still communicate with each other as could nodes 4 and 5, but communication between any other pairs of nodes would no longer be possible.
Node 3 is therefore a Single Point of Failure (SPF) for this network.
Strictly, an SPF will be defined as any node that, if unavailable, would
prevent at least one pair of available nodes from being able to
communicate on what was previously a fully connected network. Note that
the network on the right has no such node; there is no SPF in the
network. At least two machines must fail before there are any pairs of
available nodes which cannot communicate.
输入
The
input will contain the description of several networks. A network
description will consist of pairs of integers, one pair per line, that
identify connected nodes. Ordering of the pairs is irrelevant; 1 2 and 2
1 specify the same connection. All node numbers will range from 1 to
1000. A line containing a single zero ends the list of connected nodes.
An empty network description flags the end of the input. Blank lines in
the input file should be ignored.
输出
For each network in the input, you will output its number in the file, followed by a list of any SPF nodes that exist.
The first network in the file should be identified as "Network #1", the
second as "Network #2", etc. For each SPF node, output a line, formatted
as shown in the examples below, that identifies the node and the number
of fully connected subnets that remain when that node fails. If the
network has no SPF nodes, simply output the text "No SPF nodes" instead
of a list of SPF nodes.
样例输入
1 2
5 4
3 1
3 2
3 4
3 5
0
1 2
2 3
3 4
4 5
5 1
0
1 2
2 3
3 4
4 6
6 3
2 5
5 1
0
0
样例输出
Network #1
SPF node 3 leaves 2 subnets
Network #2
No SPF nodes
Network #3
SPF node 2 leaves 2 subnets
SPF node 3 leaves 2 subnets
题意
给你一个连通图,求所有割点,和去掉割点共分成几个连通图
题解
割点直接targin,求分成的连通图可以dfs整个图
代码
#include<bits/stdc++.h>
using namespace std; const int N=1e4+; vector<int>G[N];
int dfn[N],low[N],tot;
bool cut[N],vis[N];
void tarjan(int u,int fa)
{
int child=;
dfn[u]=low[u]=++tot;
for(int i=;i<G[u].size();i++)
{
int v=G[u][i];
if(!dfn[v])
{
tarjan(v,u);
low[u]=min(low[u],low[v]);
if(dfn[u]<=low[v]&&u!=fa)cut[u]=true;
if(u==fa)child++;
}
low[u]=min(low[u],dfn[v]);
}
if(u==fa&&child>=)cut[u]=true;
}
void init(int n)
{
tot=;
for(int i=;i<=n;i++)
{
G[i].clear();
dfn[i]=low[i]=;
cut[i]=false;
}
}
void dfs(int u,int no)
{
for(int i=;i<(int)G[u].size();i++)
{
int v=G[u][i];
if(!vis[v]&&v!=no)
vis[v]=true,dfs(v,no);
}
}
int main()
{
int u[N],v[N],TOT=,o=;
while(scanf("%d",&u[TOT])!=EOF,u[TOT])
{
scanf("%d",&v[TOT]);
TOT=;
while(scanf("%d",&u[TOT])!=EOF,u[TOT])
{
scanf("%d",&v[TOT]);
TOT++;
}
int n=;
for(int i=;i<TOT;i++)
n=max(n,max(u[i],v[i]));
init(n);
for(int i=;i<TOT;i++)
G[u[i]].push_back(v[i]),
G[v[i]].push_back(u[i]);
tarjan(,);
if(o-)printf("\n");
printf("Network #%d\n",o++);
vector<int>CUT;
for(int i=;i<=n;i++)if(cut[i])CUT.push_back(i);
if((int)CUT.size()==)
printf(" No SPF nodes\n");
else
{
for(int i=;i<(int)CUT.size();i++)
{
memset(vis,false,sizeof vis);
int cnt=;
for(int j=;j<=n;j++)
{
if(j==CUT[i])continue;
if(!vis[j])
cnt++,vis[j]=true,dfs(j,CUT[i]);
}
printf(" SPF node %d leaves %d subnets\n",CUT[i],cnt);
}
}
}
return ;
}
TZOJ 2018 SPF(连通图割点和分成的连通块)的更多相关文章
- TZOJ 2999 Network(连通图割点数量)
描述 A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting ...
- BZOJ 2730:[HNOI2012]矿场搭建(割点+连通块)
[HNOI2012]矿场搭建 Description 煤矿工地可以看成是由隧道连接挖煤点组成的无向图.为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路逃到救援出口处.于是矿主决定在某些挖 ...
- 【POJ 1523】SPF(割点)
儿子数大于1的树根或者 Low[v] >= DFN[u]的非树根节点v 就是割点. #include <cstdio> #include <cstring> const ...
- poj 1523 SPF 求割点以及删除该割点后联通块的数量
SPF Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7136 Accepted: 3255 Description C ...
- 【BZOJ】2730: [HNOI2012]矿场搭建【Tarjan找割点】【分联通块割点个数】
2730: [HNOI2012]矿场搭建 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3230 Solved: 1540[Submit][Stat ...
- TZOJ 2546 Electricity(去掉割点后形成的最大连通图数)
描述 Blackouts and Dark Nights (also known as ACM++) is a company that provides electricity. The compa ...
- POJ1523 SPF[无向图割点]
SPF Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8139 Accepted: 3723 Description C ...
- POJ1523 SPF(割点模板)
题目求一个无向图的所有割点,并输出删除这些割点后形成几个连通分量.用Tarjan算法: 一遍DFS,构造出一颗深度优先生成树,在原无向图中边分成了两种:树边(生成树上的边)和反祖边(非生成树上的边). ...
- POJ 1523 SPF (无向图割点)
<题目链接> 题目大意: 给你一个连通的无向图,问你其中割点的编号,并且输出删除该割点后,原图会被分成几个连通分量. 解题分析: Tarjan求割点模板题. #include <cs ...
随机推荐
- 【Linux】CentOS7 安装,遇到的各种问题,并修复win7启动项
https://www.cnblogs.com/sxdcgaq8080/p/7457255.html ------------------------------------------------- ...
- ueditor富文本框图片显示
修改config.json /* 前后端通信相关的配置,注释只允许使用多行方式 */ { /*"physicsPath":"E:/Software/apache-tomc ...
- mui页面交互
1.页面a准备函数 function hideBackBtn() { // $('.menua').removeClass('mui-icon-back').addClass('mui-icon-ba ...
- git-搭建企业git服务器
1.安装 yum install git 2.增加用户 useradd git -d /home/git -g git 3.查看公钥鉴权文件是否存在 cat /home/git/.ssh/autho ...
- li直接1px 像素的原因
1.由于空白节点(多由于Enter造成),li不换行就可以解决问题. Internet Explorer会忽略节点之间生成的空白节点,其它浏览器不会忽略(可以通过检测节点类型,过滤子节点) 2.完美解 ...
- SecureCRT使用本地公钥 SSH 免密码登录Linux
其原理与Linux系统之间的SSH通道原理是一样的 下文中如果创建公钥的格式是:标准公钥和VanDyke私钥格式,需要用ssh-keygen -i -f 转换.如果是OpenSSH密钥格式可直接修改文 ...
- HG255D刷机OPENWRT笔记
1.按网上的办法如下:(http://www.right.com.cn/forum/thread-143721-1-1.html) 自已编译了OPENWRT,然后拆开外壳接上TTL线,通电启动 然后用 ...
- TLS协议工作过程;如何应用TLS/SSL协议为WEB流量提供安全
SSL/TLS协议的基本过程是这样的: 客户端向服务器端索要并验证公钥. 双方协商生成"对话密钥". 双方采用"对话密钥"进行加密通信. 上面过程的前两 ...
- tomcat生成调试日志配置
创建文件logging.properties 文件存放于应用WEB-INF/classes下 文件内容如下: org.apache.juli.FileHandler.prefix = error-d ...
- 聚类分析K均值算法讲解
聚类分析及K均值算法讲解 吴裕雄 当今信息大爆炸时代,公司企业.教育科学.医疗卫生.社会民生等领域每天都在产生大量的结构多样的数据.产生数据的方式更是多种多样,如各类的:摄像头.传感器.报表.海量网络 ...