POJ 1966 Cable TV Network(顶点连通度的求解)
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 4678 | Accepted: 2163 |
Description
1. n, if the net remains connected regardless the number of relays removed from the net.
2. The minimal number of relays that disconnect the network when removed.

For example, consider the nets from figure 1, where the circles mark
the relays and the solid lines correspond to interconnection cables.
The network (a) is connected regardless the number of relays that are
removed and, according to rule (1), f=n=3. The network (b) is
disconnected when 0 relays are removed, hence f=0 by rule (2). The
network (c) is disconnected when the relays 1 and 2 or 1 and 3 are
removed. The safety factor is 2.
Input
a program that reads several data sets from the standard input and
computes the safety factor for the cable networks encoded by the data
sets. Each data set starts with two integers: 0<=n<=50,the number
of relays in the net, and m, the number of cables in the net. Follow m
data pairs (u,v), u < v, where u and v are relay identifiers
(integers in the range 0..n-1). The pair (u,v) designates the cable that
interconnects the relays u and v. The pairs may occur in any
order.Except the (u,v) pairs, which do not contain white spaces, white
spaces can occur freely in input. Input data terminate with an end of
file and are correct.
Output
each data set, the program prints on the standard output, from the
beginning of a line, the safety factor of the encoded net.
Sample Input
0 0
1 0
3 3 (0,1) (0,2) (1,2)
2 0
5 7 (0,1) (0,2) (1,3) (1,2) (1,4) (2,3) (3,4)
Sample Output
0
1
3
0
2
【分析】
图的连通度分为点连通度和边连通度:
(1)点连通度:只许删点,求至少要删掉几个点(当然,s和t不能删去,这里保证原图中至少有三个点);
(2)边连通度:只许删边,求至少要删掉几条边。
并且,有向图和无向图的连通度求法不同,因此还要分开考虑(对于混合图,只需将其中所有的无向边按照
无向图的办法处理、有向边按照有向图的办法处理即可)。
【1】有向图的边连通度:
这个其实就是最小割问题。以s为源点,t为汇点建立网络,原图中的每条边在网络中仍存在,容量为1,求该网络的最小割(也就是最大流)的值即为原图的边连通度。
【2】有向图的点连通度:
需要拆点。建立一个网络,原图中的每个点i在网络中拆成i'与i'',有一条边<i',
i''>,容量为1 (<s', s''>和<t', t''>例外,容量为正无穷)。原图中的每条边<i,
j>在网络中为边<i'', j'>,
容量为正无穷。以s'为源点、t''为汇点求最大流,最大流的值即为原图的点连通度。
说明:最大流对应的是最小割。显然,容量为正无穷的边不可能通过最小割,也就是原图中的边和s、t两个点不能删去;若边<i, i''>通过最小割,则表示将原图中的点i删去。
【3】无向图的边连通度:
将图中的每条边(i, j)拆成<i, j>和<j, i>两条边,再按照有向图的办法(【1】)处理;
【4】无向图的点连通度:
将图中的每条边(i, j)拆成<i, j>和<j, i>两条边,再按照有向图的办法(【2】)处理。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <vector>
#define inf 0x7fffffff
#define met(a,b) memset(a,b,sizeof a)
typedef long long ll;
using namespace std;
const int N = ;
const int M = ;
int n,m,cnt=;
int toto;
struct man
{
int u,v;
}mp[N*N];
struct Dinic {
int s,t;
struct Edge {
int nxt,to,cap,flow;
} edg[M];
bool vv[N];
bool vis[N];
int d[N];
int h[N];
int cur[N];
void init() {
met(h,-);toto=;
}
void AddEdge(int x,int y,int z) {
edg[toto].to=y;
edg[toto].nxt=h[x];
edg[toto].cap=z;edg[toto].flow=;
h[x]=toto++;
edg[toto].to=x;edg[toto].flow=;
edg[toto].nxt=h[y];
h[y]=toto++;
}
bool BFS() {
memset(vis,,sizeof(vis));met(d,-);
queue<int>q;
q.push(s);
d[s]=;
vis[s]=;
while (!q.empty()) {
int x = q.front();
q.pop();
for (int i = h[x]; i!=-; i=edg[i].nxt) {
int v=edg[i].to;
if (!vis[v] && edg[i].cap > edg[i].flow) {
vis[v]=;
d[v] = d[x]+;
q.push(v);
}
}
}
return vis[t];
} int DFS(int x,int a) {
if (x==t || a==)
return a;
int flow = ,f;
for(int &i=cur[x]; i!=-; i=edg[i].nxt) {
int v=edg[i].to;
if (d[x]+ == d[v] && (f=DFS(v,min(a,edg[i].cap-edg[i].flow)))>) {
edg[i].flow+=f;
edg[i^].flow-=f;
flow+=f;
a-=f;
if (a==)
break;
}
}
return flow;
} int Maxflow(int s,int t) {
this->s=s;
this->t=t;
int flow = ;
while (BFS()) {
for(int i=; i<=*n; i++)cur[i]=h[i];
flow+=DFS(s,inf);
}
return flow;
}
} dc;
void Build()
{
dc.init();
for(int i=;i<n;i++)dc.AddEdge(i,i+n,);
for(int i=;i<m;i++){
dc.AddEdge(mp[i].u+n,mp[i].v,inf);
dc.AddEdge(mp[i].v+n,mp[i].u,inf);
}
}
int main() {
int u,v;
while(~scanf("%d%d",&n,&m)){
met(mp,);int ans=inf;int pp[N][N];
met(pp,);
for(int i=;i<m;i++){
scanf(" (%d,%d)",&u,&v);
mp[i].u=u;mp[i].v=v;pp[u][v]=pp[v][u]=;
}
for(int i=;i<n;i++){
for(int j=i+;j<n;j++){
Build();
if(!pp[i][j]){ans=min(ans,dc.Maxflow(i+n,j));if(ans==)break;}
}
if(ans==)break;
}
if(abs(ans)>=n)ans=n;
printf("%d\n",ans);
}
return ;
}
POJ 1966 Cable TV Network(顶点连通度的求解)的更多相关文章
- poj 1966 Cable TV Network 顶点连通度
题目链接 给一个图, n个点m条边, 求至少去掉多少个点可以使得图不再联通.随便指定一个点为源点, 枚举其他点为汇点的情况, 跑网络流, 求其中最小的情况. 如果最后ans为inf, 说明是一个完全图 ...
- Cable TV Network 顶点连通度 (最大流算法)
Cable TV Network 题目抽象:给出含有n个点顶点的无向图,给出m条边.求定点联通度 K 算法:将每个顶点v拆成 v' v'' ,v'-->v''的容量为1. ...
- POJ 1966 Cable TV Network
Cable TV Network Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4702 Accepted: 2173 ...
- POJ 1966 Cable TV NETWORK(网络流-最小点割集)
Cable TV NETWORK The interconnection of the relays in a cable TV net ...
- POJ 1966 Cable TV Network (点连通度)【最小割】
<题目链接> 题目大意: 给定一个无向图,求点连通度,即最少去掉多少个点使得图不连通. 解题分析: 解决点连通度和边连通度的一类方法总结见 >>> 本题是求点连通度, ...
- POJ 1966 Cable TV Network (无向图点连通度)
[题意]给出一个由n个点,m条边组成的无向图.求最少去掉多少点才能使得图中存在两点,它们之间不连通. [思路]回想一下s->t的最小点割,就是去掉多少个点能使得s.t不连通.那么求点连通度就枚举 ...
- POJ 1966 Cable TV Network (算竞进阶习题)
拆点+网络流 拆点建图应该是很常见的套路了..一张无向图不联通,那么肯定有两个点不联通,但是我们不知道这两个点是什么. 所以我们枚举所有点,并把每个点拆成入点和出点,每次把枚举的两个点的入点作为s和t ...
- POJ 1966 Cable TV Network 【经典最小割问题】
Description n个点的无向图,问最少删掉几个点,使得图不连通 n<=50 m也许可以到完全图? Solution 最少,割点,不连通,可以想到最小割. 发现,图不连通,必然存在两个点不 ...
- POJ - 1966 Cable TV Network (最大流求点连通度)
题意:求一个无向图的点连通度.点联通度是指,一张图最少删掉几个点使该图不连通:若本身是非连通图,则点连通度为0. 分析:无向图的点连通度可以转化为最大流解决.方法是:1.任意选择一个点作为源点:2.枚 ...
随机推荐
- vue js 用nodejs的依赖包 --2016-08-23
今天被nodejs包依赖坑了一下,上次上传的项目突然运行不起来了,原来是package.json中定义了使用最新版本的依赖,而最新版本有可能调整了结构或者改了api,比如vux把flexbox-it ...
- [转]android Intent机制详解
转自:http://blog.csdn.net/t12x3456/article/details/7688154 1.什么是Intent Intent是一种运行时绑定(run-time binding ...
- Cannot change network to bridged: There are no un-bridged host network adapters解决方法
首先,在你安装上了虚拟机后要确保你也安装了桥接的协议,这可以通过点击右键“网上邻居”,在其中可以看到有两个虚拟出来的网络一个VMnet1,另一个是VMnet8, 如下图所示. 如果没有安装,可以通过下 ...
- word表格从 web版视图 转 到页面视图 模式后 表格的一部分显示不出来
解决办法 在web视图 中选择 表格 ----->右键 表格属性 表格 下面 的 文字环绕 选择 无
- centos下安装node js
#wget http://nodejs.org/dist/v0.10.24/node-v0.10.24.tar.gz #tar xf node-v0.10.24.tar.gz #cd node-v0. ...
- 码表由来:ascll码-Gbk2312-GBK-Unicode-UTF-8
码表ascll码-Gbk2312-GBK-Unicode-UTF-8, ascll是基本的标准码表,GB2312是中文码表,GBK是扩展之后的码表,Unicode是国际通用码表,UTF-8是优化后的U ...
- GCD的用法
单例的实现 + (BindingRedResourceWIndow *)sharedInstance { static id sharedInstance = nil; static dispatch ...
- [转] linux中巧用ctrl-z后台运行程序
背景: 最近在执行一些长时间程序的时候,老是一不小心忘了输入‘&’ , 结果终端就卡在那里了,很是郁闷 以前总是再新开一个终端. 今天翻看<鸟哥的linux私房菜>的时候,发现介绍 ...
- jsp弹出Please check the location and try again!对话框
关闭它的jsp图形模式.myeclipse10中打开jsp文件时,右键open with 选MyEclipse JSP Editor,不选MyEclipse Visual JSP Editor模式.
- VS2013失去智能提示如何恢复
一般智能提示包括,输入智能提示,鼠标移到类,方法,接口,变量上面自动提示相关信息,VS2013常常会失去这种提示功能,遇到这种情况可以这样解决: 1.在开发环境中随便打开一个xxx.aspx页面,也就 ...