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 ...
随机推荐
- day42-多线程与多进程
一 进程与线程的概念 1.1 进程 考虑一个场景:浏览器,网易云音乐以及notepad++ 三个软件只能顺序执行是怎样一种场景呢?假如有两个程序A和B,程序A在执行到一半的过程中,需要读取大量的数据输 ...
- TWebBrowser禁止弹出Alert对话框
以前介绍过通过编写Webbrowser1的OnDocumentComplete事件响应代码可以拦截网页弹出的Alert等对话框,代码如下: procedure TForm1.WebBrowser1Do ...
- (笨方法)利用stat函数实现ls -l filename
学习了一段时间的Linux了,但是我感觉我做不出来啥子,后头选择利用系统IO函数实现命令,先从ls走起吧.先来看看ls -l filename给我们显示了什么吧 : 可以看到,一共八项:文件类型.用户 ...
- 虚拟机安装VMware tools
选择虚拟机菜单栏--安装VMware tools 2 然后在CentOS系统中弹出的VMware tools窗口中 右击VMwaretools-9.6.0-1294478.tar.gz 解压缩到 3 ...
- vue项目插入视频-mp4
1. v.vue文件: <template> <div> <div class="contain"> <my-video :sources ...
- Android进阶AIDL - 2018年4月14日
参考:慕课网 --- 最后三集.Android开发艺术探索 1.在AS中创建aidl文件后,要编译一下才会在gen下生成debug文件: 2.AIDL 不支持short类型,常用的数据类型: 3.AI ...
- jQuery中的end()方法
定义和用法 end() 方法结束当前链条中的最近的筛选操作,并将匹配元素集还原为之前的状态. 以上是官方说法,比较难理解. 还是用一个例子来说明 <!DOCTYPE html> <h ...
- centos6.5下oracle自动备份删除指定天数的文件
第一步先做一个备份 #!/bin/sh export ORACLE_BASE=/home/oracle/app export ORACLE_HOME=/dbhome_1 export ORACLE_S ...
- C++ MFC 改变控件大小和位置
用CWnd类的函数MoveWindow()或SetWindowPos()可以改变控件的大小和位置. void MoveWindow(int x,int y,int nWidth,int nHeight ...
- openstack常用命令
共享镜像 glance member-create fa47923c-2d3b-4d71-80cf-a047ba3bf342 eb3913b9ae5f41b09f2632389a1958d8删除共享镜 ...