POJ 1966 Cable TV Network
Cable TV Network
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 Sample Output 0 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 |
[Submit] [Go Back] [Status] [Discuss]
将原图中每个点拆成两个点,分别为入点和出点,从入点向出点连一条容量为1的边,代表割掉这个点的费用为1。
对于原图中的一条边(x,y),连一条x的出点到y的入点容量为正无穷的边,以及一条y的出点到x的入点容量为正无穷的边。
枚举新图中的S和T,S在出点中枚举,T在入点中枚举,求最小割,更新答案。
#include <cstdio>
#include <cstring> const int inf = 2e9;
const int maxn = ; inline int nextInt(void)
{
register int ret = ;
register int neg = false;
register int bit = getchar(); for (; bit < ; bit = getchar())
if (bit == '-')neg ^= true; for (; bit > ; bit = getchar())
ret = ret * + bit - ; return neg ? -ret : ret;
} template <class T>
inline T min(T a, T b)
{
return a < b ? a : b;
} int n, m;
int s, t;
int edges;
int hd[maxn];
int nt[maxn];
int to[maxn];
int fl[maxn];
int bp[maxn]; inline void add(int u, int v, int f)
{
nt[edges] = hd[u]; to[edges] = v; fl[edges] = f; hd[u] = edges++;
nt[edges] = hd[v]; to[edges] = u; fl[edges] = ; hd[v] = edges++;
} int dep[maxn]; inline bool bfs(void)
{
static int que[maxn];
static int head, tail; memset(dep, , sizeof(dep));
head = , tail = ;
que[tail++] = s;
dep[s] = ; while (head != tail)
{
int u = que[head++], v;
for (int i = hd[u]; ~i; i = nt[i])
if (!dep[v = to[i]] && fl[i])
dep[v] = dep[u] + , que[tail++] = v;
} return dep[t];
} int dfs(int u, int f)
{
if (u == t || !f)
return f; int used = , flow, v; for (int i = hd[u]; ~i; i = nt[i])
if (dep[v = to[i]] == dep[u] + && fl[i])
{
flow = dfs(v, min(f - used, fl[i])); used += flow;
fl[i] -= flow;
fl[i^] += flow; if (used == f)
return f;
} if (!used)
dep[u] = ; return used;
} inline int maxFlow(void)
{
int maxFlow = , newFlow; while (bfs())
while (newFlow = dfs(s, inf))
maxFlow += newFlow; return maxFlow;
} signed main(void)
{
while (~scanf("%d%d", &n, &m))
{
memset(hd, -, sizeof(hd)), edges = ; for (int i = ; i <= m; ++i)
{
int u = nextInt();
int v = nextInt(); add(u << , v << | , inf);
add(v << , u << | , inf);
} for (int i = ; i < n; ++i)
add(i << | , i << , ); memcpy(bp, fl, sizeof(bp)); int ans = inf; for (int i = ; i < n; ++i)
for (int j = ; j < n; ++j)
if (i != j)
{
s = i << ;
t = j << | ;
memcpy(fl, bp, sizeof(fl));
ans = min(ans, maxFlow());
} printf("%d\n", ans == inf ? n : ans);
}
}
@Author: YouSiki
POJ 1966 Cable TV Network的更多相关文章
- POJ 1966 Cable TV Network(顶点连通度的求解)
Cable TV Network Time Limit: 1000MS Memory Limit: 30000K Total Submissi ...
- POJ 1966 Cable TV NETWORK(网络流-最小点割集)
Cable TV NETWORK The interconnection of the relays in a cable TV net ...
- POJ 1966 Cable TV Network (无向图点连通度)
[题意]给出一个由n个点,m条边组成的无向图.求最少去掉多少点才能使得图中存在两点,它们之间不连通. [思路]回想一下s->t的最小点割,就是去掉多少个点能使得s.t不连通.那么求点连通度就枚举 ...
- poj 1966 Cable TV Network 顶点连通度
题目链接 给一个图, n个点m条边, 求至少去掉多少个点可以使得图不再联通.随便指定一个点为源点, 枚举其他点为汇点的情况, 跑网络流, 求其中最小的情况. 如果最后ans为inf, 说明是一个完全图 ...
- POJ 1966 Cable TV Network (点连通度)【最小割】
<题目链接> 题目大意: 给定一个无向图,求点连通度,即最少去掉多少个点使得图不连通. 解题分析: 解决点连通度和边连通度的一类方法总结见 >>> 本题是求点连通度, ...
- 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.枚 ...
- POJ 1966 Cable TV Network (最大流最小割)
$ POJ~1966~Cable~TV~Network $ $ solution: $ 第一眼可能让人很难下手,但本就是冲着网络流来的,所以我们直接一点.这道题我们要让这个联通图断开,那么势必会有两个 ...
随机推荐
- Android 手机卫士8--删除通话记录
1.编写代码需要注意bug: 再删除通话记录的时候,删除的是以前的通话记录,本次拦截下来的电话号码,通话记录没有删除?????? 问题原因:数据库中本次通话记录的电话号码还没有插入,就做了删除操作 2 ...
- javascript代码 调试方法
你的代码可能包含语法错误,逻辑错误,如果没有调试工具,这些错误比较难于发现. 通常,如果 JavaScript 出现错误,是不会有提示信息,这样你就无法找到代码错误的位置. 在程序代码中寻找错误叫做代 ...
- Xming + PuTTY 在Windows下远程Linux主机使用图形界面的程序
安装X Window yum groupinstall 'X Window System'
- Microsoft Dynamics CRM 2013 的相关更新 2013-12
DCRM 2013已经发布一段时间了,很多同学都在学习实践中. 截至目前,已经有了一些相关的更新,具体内容,可以参见web Page:http://blogs.msdn.com/b/c ...
- Android关于listView的BaseAdapter以及getView的三级优化
1.4个重写方法的含义 自定义Adapter继承自BaseAdapter(通用适配器) getCount(); getItem(); getItemId(); getViewTypaCount() ...
- 整理UIImagePickerController问题
[assetsLibrary addAssetsGroupAlbumWithName:@"iOSDevTip1" resultBlock:^(ALAssetsGroup *grou ...
- UINavigationController
知识点: 1)UINavigationController 2)UINavigationBar 3)UINavigationItem 4)UIToolBar ===================== ...
- MySQL 5.7.10 自动备份、自动清理旧备份集
http://blog.csdn.net/mchdba/article/details/51527081 MySQL版本是5.7.10-log社区版本,需要进行备份,但是备份时间长了后,磁盘不够用,所 ...
- jquery $.each终止本次循环
1.for循环中我们使用continue:终止本次循环计入下一个循环,使用break终止整个循环. 2.而在jquery中 $.each则对应的使用return true 进入下一个循环,return ...
- IT人士怎样的休息方式才高效
为什么你睡了11个小时仍然觉得疲累? 为什么你花了好几万去岛国度假并没有增加生活的热情? 都说要去KTV,去夜店,去游乐园就能忘掉不快,更带劲地开始新的一天,但是尽兴归来心里只剩空虚? 我们真的明白休 ...