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 ...
随机推荐
- Installing PHP5 on Ubuntu Server
When installing PHP 5 from source I ran into the following problems and solutions: Problem:configure ...
- 【JEECG技术文档】Online唯一校验使用说明
1.功能介绍 配置了唯一校验的字段,在录入和编辑页面中,动态查询用户输入值是否存在校验. 要使用online唯一校验功能必须先在online表单开发中配置唯一字段的校验方式为唯一校验. 2.配置唯一校 ...
- css3-animate
常用动画设置: effect easing duration effect: <select name="effects" id="effectTypes&quo ...
- spring boot 的常用注解
SpringBoot用于简化Spring应用的搭建,开发及部署:该框架采用注解的方式进行配置可以很方便的构建Spring应用. 1. @SpringBootApplication @SpringBoo ...
- JSP页面java代码报错:Purgoods cannot be resolved to a type
错误提示 : Purgoods cannot be resolved to a type Purgoods不能解析为一个类型 原因 : 缺少引入Purgoods类 页面中引入java类,执行java代 ...
- spring集成mybatis的mybatis参考配置
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE configuration PUBLIC &q ...
- kbengine:简单介绍
之前想分析一个开源服务器很久了,思前想后,还是选择了kbengine. KBEngine的服务端底层框架使用c++编写,游戏逻辑层使用Python(支持热更新).现在服务器大多数是用C++做的,pyt ...
- angular的启动原理
当你用浏览器去访问index.html的时候,浏览器依次做了如下一些事情: 加载html,然后解析成DOM: 加载angular.js脚本:加载完成后自执行,生成全局angular对象,监听DOMCo ...
- Oracle VM VirtualBox各种显示模式切换 热键
初用VirtualBox, 几个显示切换快捷键还是要记一下的: Right Ctrl + F -- 切换到全屏模式 Right Ctrl + L -- 切换到无缝模式 Ri ...
- 【371】Twitter 分类相关
Bag-of-words model:就是将句子打散成单词的集合. N-gram model:同上,只是按照 n 进行顺序组合. 参考:机器学习实战教程(四):朴素贝叶斯基础篇之言论过滤器 留言板侮辱 ...