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 ...
随机推荐
- hive基础操作
hive --version 查看hive的版本 hive -S -e "set" | grep auto ##在shell下可以查找属性的状态.小技巧.
- 页面中的checkbox多选值获取
依据name名称获取选中值 var arr=document.getElementsByName("name");arr是一个数组,就是所有checkbox的值:for(i=0;i ...
- Zookeeper 基本应用及盲点
主要应用 From: https://segmentfault.com/a/1190000012185452 http://blog.fens.me/zookeeper-queue/ 原理: 应用zo ...
- Zabbix笔记
简单检查中的icmppingloss[<target>,<packets>,<interval>,<size>,<timeout>] 结 ...
- python 验证码test
灰度化 #coding:utf8 import re import urllib import urllib2 import requests from PIL import Image import ...
- 手动安裝TMG2010所需Windows服务和功能
安装 Forefront TMG 之前,必须运行准备工具,以验证是否已在您的计算机上安装成功安装 Forefront TMG 所需的应用程序.如果在未首先运行准备工具的情况下运行 Forefront ...
- Python 如何创建2维空数组
http://blog.csdn.net/yockie/article/details/46127829 myList = [ ( [0] * 3 ) for i in range(4) ] > ...
- tensorflow中run和eval的区别(转)
在tensorflow中,eval和run都是获取当前结点的值的一种方式. 在使用eval时,若有一个 t 是Tensor对象,调用t.eval()相当于调用sess.run(t) 一下两段代码等效: ...
- workerman Channel组件全局广播
<?phpuse Workerman\Worker; require_once '../../web/Workerman/Autoloader.php';require_once '../../ ...
- struts2漏洞信息
渗透篇01-struts2漏洞利用 https://blog.csdn.net/qq_38055050/article/details/79841604 Struts2著名RCE漏洞引发的十年之思 ...