Cable TV Network-POJ1966图的连通度
Cable TV Network
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 4404 Accepted: 2047
Description
The interconnection of the relays in a cable TV network is bi-directional. The network is connected if there is at least one interconnection path between each pair of relays present in the network. Otherwise the network is disconnected. An empty network or a network with a single relay is considered connected. The safety factor f of a network with n relays is:
- n, if the net remains connected regardless the number of relays removed from the net.
- 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
Write 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
For 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
Hint
The first data set encodes an empty network, the second data set corresponds to a network with a single relay, and the following three data sets encode the nets shown in figure 1.
Source
Southeastern Europe 2004
本题求的是图的连通度,应用的是Menger定理,采用计算两点之间独立轨的数目,来计算图的连通度。
/*求图的连通度,应用Menger定理,
*即无向图G的顶点连通度K(G)与顶点间的最大独立轨数目之间的关系
*if G是完全图
K{G}=|V(G)|-1
*else
K(G)=min(P{A,B}) A,B不相邻
*
*/
#include <cstdio>
#include <cstring>
#include <queue>
#include <cstdlib>
#include <algorithm>
#define LL long long
using namespace std;
const int Max = 110;
const int INF = 0x3f3f3f3f;
int Map[Max][Max];
int MaxFlow(int n,int s,int t)
{
int Flow[Max][Max]; //记录当前网络的流。
int MinFlow[Max];//记录路径上的最小值
int pre[Max];//记录父节点
queue<int>Q;
int ans = 0;
memset(Flow,0,sizeof(Flow));
while(1)
{
while(!Q.empty())
{
Q.pop();
}
Q.push(s);
memset(pre,-1,sizeof(pre));
pre[s] = -2;
MinFlow[s]=INF;
while(!Q.empty())
{
int u = Q.front();
Q.pop();
for(int i=0;i<n;i++)
{
if(pre[i]==-1&&Flow[u][i]<Map[u][i])
{
pre[i]=u;
Q.push(i);
MinFlow [i] = min(MinFlow[u],(Map[u][i]-Flow[u][i]));
}
}
if(pre[t]!=-1)//判断是否存在增广轨。
{
int k = t;
while(pre[k]>=0)
{
Flow[pre[k]][k]+=MinFlow[t];
Flow[k][pre[k]]-=MinFlow[t];
k = pre[k];
}
break;
}
}
if(pre[t]==-1)
{
return ans;
}
else
{
ans += MinFlow[t];
}
}
}
int n,m;
int main()
{
while(~scanf("%d %d:",&n,&m))
{
int u,v;
memset(Map,0,sizeof(Map));
for(int i=0;i<n;i++)
{
Map[i][i+n]=1;
}
for(int i=1;i<=m;i++)
{
scanf(" (%d,%d)",&u,&v);
Map[u+n][v]=Map[v+n][u]=INF;
}
int ans = INF;
for(int i=1;i<n;i++)//枚举找最小的独立轨的数目
{
ans = min(ans,MaxFlow(n*2,n,i));
}
if(ans == INF)
{
ans = n;
}
printf("%d\n",ans);
}
return 0;
}
Cable TV Network-POJ1966图的连通度的更多相关文章
- POJ 1966 Cable TV Network(顶点连通度的求解)
Cable TV Network Time Limit: 1000MS Memory Limit: 30000K Total Submissi ...
- 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 ...
- UVA1660 电视网络 Cable TV Network
题目地址:UVA1660 电视网络 Cable TV Network 枚举两个不直接连通的点 \(S\) 和 \(T\) ,求在剩余的 \(n-2\) 个节点中最少去掉多少个可以使 \(S\) 和 \ ...
- POJ 1966 Cable TV NETWORK(网络流-最小点割集)
Cable TV NETWORK The interconnection of the relays in a cable TV net ...
- UVA 1660 Cable TV Network 电视网络(无向图,点连通度,最大流)
题意:给一个无向图,求其点连通度?(注意输入问题) 思路: 如果只有1个点,那么输出“1”: 如果有0条边,那么输出“0”: 其他情况:用最大流解决.下面讲如何建图: 图的连通度问题是指:在图中删去部 ...
- UVALIVE 3031 Cable TV Network
题意:求点联通度 首先看了别人的题解还是不晓得只枚举汇点的原因觉得行不通 关于求点联通度的建图方法 转自http://hi.baidu.com/lerroy312/item/5a5f36f2f5bba ...
- 求割点模板(可求出割点数目及每个割点分割几个区域)POJ1966(Cable TV Network)
题目链接:传送门 题目大意:给你一副无向图,求解图的顶点连通度 题目思路:模板(图论算法理论,实现及应用 P396) Menger定理:无向图G的顶点连通度k(G)和顶点间最大独立轨数目之间存在如下关 ...
- poj 1966 Cable TV Network 顶点连通度
题目链接 给一个图, n个点m条边, 求至少去掉多少个点可以使得图不再联通.随便指定一个点为源点, 枚举其他点为汇点的情况, 跑网络流, 求其中最小的情况. 如果最后ans为inf, 说明是一个完全图 ...
- POJ1966 Cable TV Network
原题链接 割去点使得无向图不连通,和最小割相似. 我们可以将点转化成边,这样就能跑最小割了. 枚举每两个不能直接到达的点\(S,T\),使得删去一些点(除去这两个点)使得这两个点不连通(若两点能直接到 ...
随机推荐
- centos6 LVS-DR模式---分析
LVS是什么就不多说了. 先上拓扑图 1台LVS 3台Realserver 一个客户端. 环境全部模拟全在内网环境(selinux和iptables关闭) 先简略说一下安装步骤: LVS上 ...
- 关于UGUI Image Sliced模式的一个BUG。
Unity4.6.2f1 在Android/IOS平台下,Image选择Sliced模式,并且对Sprite设置好Border后,会发现并没有按照预计的 情况进行拉伸. 搜了一下是因为Sprite的G ...
- PHP文件操作系统----主要的文件操作函数
一.文件操作系统概述 1.概述: php中的文件操作系统主要是对文件和目录的操作.文件在windows系统下分为3种不同:文件.目录.未知,在linux/unix系统下分为7种不同:block.cha ...
- markdown 设置字体颜色
<font color=red>内容</font> markdown.
- java线程生命周期及其对应方法
http://blog.sina.com.cn/s/blog_a8aa82cc0101ktrm.html http://wenku.baidu.com/view/c242df69011ca300a6c ...
- Javascript模块化编程(二):AMD规范 作者: 阮一峰
声明:转载自阮一峰的网络日志 这个系列的第一部分介绍了Javascript模块的基本写法,今天介绍如何规范地使用模块. (接上文) 七.模块的规范 先想一想,为什么模块很重要? 因为有了模块,我们就可 ...
- Pivot C# WPF 代码添加PivotItem
PivotItem new_PivotItem = new PivotItem();//新建Pivotitem ListView new_ListView = new ListView();//新建l ...
- PartialViewResult不鸟_ViewStart.cshtml
概述 在ASP.NET MVC中,对于Action中得到的ActionResult如果是一个ViewResult对象,那么在进行View呈现时,则会先执行_ViewStart.cshtml,然后再去执 ...
- 系统隐式 Intent
1. 找出系统中所有视频 private void choiceFile() { Intent intent = new Intent(Intent.ACTION_PICK, android.prov ...
- 由SecureCRT引发的思考和学习
由SecureCRT引发的思考和学习 http://mp.weixin.qq.com/s?__biz=MzAxOTAzMDEwMA==&mid=2652500597&idx=1& ...