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. SQL 参数化查询 应用于 Like

    在sql 进行参数化查询的时候,使用like 语句和参数的时候,错误的写法:  Participant like '%@Participant%' ,这样在数据库为解析为 '%'participant ...

  2. 汇编寄存器(内存访问)基础知识之三---mov指令

     1 内存中字的存储 一个字型数据占2个内存单元,内存里面一个内存单元一个字节(8位),高地址单位放高8位,低地址单元放低8位. 注意:0号是地址单元,1是高地址单元(上是低地址,下面是高地址) (1 ...

  3. ASCII值对照表

    说明:这里的ascii的值是十进制的 ASCII值 控制字符 ASCII值 控制字符 ASCII值 控制字符 ASCII值 控制字符 0 NUT 32 (space) 64 @ 96 . 1 SOH ...

  4. Linux下JDK安装笔记

    环境说明: Linux版本: CentOS6.2   JDK:jdk-7u60-linux-x64.tar.gz 1.下载jdk-7u60-linux-x64.tar.gz,本人是放到了~/工具 目录 ...

  5. 一个简单驱动的makefile

    KVERS = $(shell uname -r) #Kernel modulesobj-m += hello.o build: kernel_modules kernel_modules: make ...

  6. Bash中各种以$开头的特殊变量的含义

    $$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行的命令的结束代码(返回值) $- 使用Set命令设定的Flag一览 $* 所有参 ...

  7. PHP关于依赖注入(控制反转)的解释和例子说明

    PHP关于依赖注入(控制反转)的解释和例子说明 发表于2年前(2014-03-20 10:12)   阅读(726) | 评论(1) 8人收藏此文章, 我要收藏 赞2 阿里云双11绽放在即 1111 ...

  8. mysql单表多timestamp的current_timestamp设置问题

    一个表中出现多个timestamp并设置其中一个为current_timestamp的时候经常会遇到 1293 - Incorrect table definition; there can be o ...

  9. Thinking in Java——笔记(7)

    Reusing Classes The first is composition,You're simply reusing the functionality of the code, not it ...

  10. Git: untrack a file in local repo only and keep it in the remote repo

    You could update your index: git update-index --assume-unchanged nbproject/project.properties and ma ...