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:

  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

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图的连通度的更多相关文章

  1. POJ 1966 Cable TV Network(顶点连通度的求解)

                               Cable TV Network Time Limit: 1000MS   Memory Limit: 30000K Total Submissi ...

  2. Cable TV Network 顶点连通度 (最大流算法)

    Cable TV Network 题目抽象:给出含有n个点顶点的无向图,给出m条边.求定点联通度   K 算法:将每个顶点v拆成 v'   v''  ,v'-->v''的容量为1.       ...

  3. POJ 1966 Cable TV Network

    Cable TV Network Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 4702   Accepted: 2173 ...

  4. UVA1660 电视网络 Cable TV Network

    题目地址:UVA1660 电视网络 Cable TV Network 枚举两个不直接连通的点 \(S\) 和 \(T\) ,求在剩余的 \(n-2\) 个节点中最少去掉多少个可以使 \(S\) 和 \ ...

  5. POJ 1966 Cable TV NETWORK(网络流-最小点割集)

                                    Cable TV NETWORK The interconnection of the relays in a cable TV net ...

  6. UVA 1660 Cable TV Network 电视网络(无向图,点连通度,最大流)

    题意:给一个无向图,求其点连通度?(注意输入问题) 思路: 如果只有1个点,那么输出“1”: 如果有0条边,那么输出“0”: 其他情况:用最大流解决.下面讲如何建图: 图的连通度问题是指:在图中删去部 ...

  7. UVALIVE 3031 Cable TV Network

    题意:求点联通度 首先看了别人的题解还是不晓得只枚举汇点的原因觉得行不通 关于求点联通度的建图方法 转自http://hi.baidu.com/lerroy312/item/5a5f36f2f5bba ...

  8. 求割点模板(可求出割点数目及每个割点分割几个区域)POJ1966(Cable TV Network)

    题目链接:传送门 题目大意:给你一副无向图,求解图的顶点连通度 题目思路:模板(图论算法理论,实现及应用 P396) Menger定理:无向图G的顶点连通度k(G)和顶点间最大独立轨数目之间存在如下关 ...

  9. poj 1966 Cable TV Network 顶点连通度

    题目链接 给一个图, n个点m条边, 求至少去掉多少个点可以使得图不再联通.随便指定一个点为源点, 枚举其他点为汇点的情况, 跑网络流, 求其中最小的情况. 如果最后ans为inf, 说明是一个完全图 ...

  10. POJ1966 Cable TV Network

    原题链接 割去点使得无向图不连通,和最小割相似. 我们可以将点转化成边,这样就能跑最小割了. 枚举每两个不能直接到达的点\(S,T\),使得删去一些点(除去这两个点)使得这两个点不连通(若两点能直接到 ...

随机推荐

  1. 无损破解Android图案密码及原理

    作者:http://weibo.com/hellguard 安卓图案密码穷举,秒破gesture.key.图案密码是明文的SHA1,明文取值范围是[00-08],不超过9字节,不重复出现,没有SALT ...

  2. mysql sql注入

    防止SQL注入,我们需要注意以下几个要点: 1.永远不要信任用户的输入.对用户的输入进行校验,可以通过正则表达式,或限制长度:对单引号和 双"-"进行转换等. 2.永远不要使用动态 ...

  3. 讨论一下js获取响应中后台传回来的BigInteger类型的数字时,后几位会自动变为0的问题

    后台返回的json:{"data":12345678912345678912} 在js中获取该data得到的值为:12345678912345680000 后经过实验发现,只有数字 ...

  4. 上传读取Excel文件数据

    /// <summary> /// 上传读取Excel文件数据 /// 来自http://www.cnblogs.com/cielwater /// </summary> // ...

  5. Bootstrap Chart组件使用分享

    图表组件Chart.js是Bootstrap比较好用的组件之一,与一款收费的组件highchart类似,效果上来看免费与收费的产品相差还是有一点点的,不过功能上差不多能满足我们项目的需要.下面这段JS ...

  6. BizTalk开发系列(十五) Schema设计之Qualified 与Unqualified

    XML Schema中的命名空间前缀限定包括对元素(Element)或属性(Attribute)的限定,即常见的如 “<ns0:root>...</ns0:root>”之类的格 ...

  7. php课程---建立一个简单的下拉列表框

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. Java程序设计 实验三

    北京电子科技学院(BESTI) 实     验    报     告 课程:Java程序设计   班级:1353       姓名:李海空  学号:20135329 成绩:             指 ...

  9. request实现页面包含

    package cn.itcast.request; import java.io.IOException; import javax.servlet.ServletException; import ...

  10. jquery on()方法绑定多个选择器,多个事件

    on(events,[selector],[data],fn) •events:一个或多个用空格分隔的事件类型和可选的命名空间,如"click"或"keydown.myP ...