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\),使得删去一些点(除去这两个点)使得这两个点不连通(若两点能直接到 ...
随机推荐
- .net 文件下载【转】
方式一:TransmitFile实现下载.将指定的文件直接写入 HTTP 响应输出流,而不在内存中缓冲该文件. protected void Button1_Click(object send ...
- javascript 百度地图
官方地址 http://lbsyun.baidu.com/index.php?title=jspopular 示例地址 http://developer.baidu.com/map/jsdemo.ht ...
- MyEclipse不能重新发布的解决方案
myeclipse2015已发布项目上右键clear不重新发布的解决方案: 该项目在server.xml中没有设置自动发布reloadable="true"
- BizTalk开发系列(十) ESB Guidance安装笔记
ESB指导工具包(ESB Guidance)是一个运行于BizTalk Server 2006 R2之上的一个框架.详细信息访问ESB指导工具包社区网站 .源码下载 ESB Guidance的安装过程 ...
- xml案例(考生成绩管理系统)
package itacst.dao; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node ...
- Redis和Memcache对比及选择(转载)
- Python之编写函数
Python之编写函数 在Python中,定义一个函数要使用 def 语句,依次写出函数名.括号.括号中的参数和冒号:,然后,在缩进块中编写函数体,函数的返回值用 return 语句返回. 我们以自定 ...
- TypedValue.applyDimension 中dp和sp之间转化的真相
转载自http://www.cnblogs.com/xilinch/p/4444833.html 最近在看了许多关于dp-px,px-dp,sp-px,px-sp之间转化的博文,过去我比较常用的方式是 ...
- 基于XMPP协议(openfire服务器)的消息推送实现
转自:http://blog.csdn.net/nomousewch/article/details/8088277 最近好像有不少朋友关注Android客户端消息推送的实现,我在之前的项目中用到过J ...
- ERROR 2006 (HY000) at line xx: MySQL server has gone away 解决方法