uva 1660 & poj 1966(点连通度)
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 4267 | Accepted: 2003 |
Description
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
Output
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
Source

图的连通度问题是指:在图中删去部分元素(点或边),使得图中指定的两个点s和t不连通 (不存在从s到t的路径),求至少要删去几个元素。
图的连通度分为点连通度和边连通度:
(1)点连通度:只许删点,求至少要删掉几个点(当然,s和t不能删去,这里保证原图中至少有三个点);
(2)边连通度:只许删边,求至少要删掉几条边。
并且,有向图和无向图的连通度求法不同,因此还要分开考虑(对于混合图,只需将其中所有的无向边按照
无向图的办法处理、有向边按照有向图的办法处理即可)。
【1】有向图的边连通度:
这个其实就是最小割问题。以s为源点,t为汇点建立网络,原图中的每条边在网络中仍存在,容量为1,求该网络的最小割(也就是最大流)的值即为原图的边连通度。
【2】有向图的点连通度:
需要拆点。建立一个网络,原图中的每个点i在网络中拆成i'与i'',有一条边<i', i''>,容量为1 (<s', s''>和<t', t''>例外,容量为正无穷)。原图中的每条边<i, j>在网络中为边<i'', j'>,
容量为正无穷。以s'为源点、t''为汇点求最大流,最大流的值即为原图的点连通度。
说明:最大流对应的是最小割。显然,容量为正无穷的边不可能通过最小割,也就是原图中的边和s、t两个点不能删去;若边<i, i''>通过最小割,则表示将原图中的点i删去。
【3】无向图的边连通度:
将图中的每条边(i, j)拆成<i, j>和<j, i>两条边,再按照有向图的办法(【1】)处理;
【4】无向图的点连通度:
将图中的每条边(i, j)拆成<i, j>和<j, i>两条边,再按照有向图的办法(【2】)处理。
关键就是建图,然而我并不懂为什么这样建。。。
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define repd(i, a, b) for(int i = b; i >= a; i--)
#define sfi(n) scanf("%d", &n)
#define pfi(n) printf("%d\n", n)
#define sfi2(n, m) scanf("%d%d", &n, &m)
#define pfi2(n, m) printf("%d %d\n", n, m)
#define pfi3(a, b, c) printf("%d %d %d\n", a, b, c)
#define MAXN 105
#define V 55
const int INF = 0x3f3f3f3f;
int edge[V][V];
int N,M;
int n,m;
#define maxn 210
const int inf = 0x3f3f3f3f; struct EK
{
int cap[maxn][maxn];
int flow[maxn][maxn];
int n;
void init(int n)
{
this->n = n;
memset(cap, , sizeof(cap));
}
void addCap(int i, int j, int val)
{
cap[i][j] = val;
}
int solve(int source, int sink)
{
if(source == sink) return inf;///源=汇, 流量无穷大!
static int que[maxn], pre[maxn], d[maxn];
///bfs时的队列; bfs时某点的前驱; 增光路径的流量
int p, q, t;///bfs时的队列底、顶; bfs时当前元素
memset(flow, , sizeof(flow));
while(true)
{
memset(pre, , sizeof(pre));
d[source] = inf;
p = q = ;
que[q ++] = source; while(p<q && pre[sink]==-)
{
t = que[p ++];
for(int i = ; i < n; i ++) //注意下标
{
if(pre[i]==- && cap[t][i]-flow[t][i]>)
{
///残余=cap-flow
pre[i] = t;
que[q++]=i;
d[i] = min(d[t], cap[t][i]-flow[t][i]);
}
}
}
if(pre[sink]==-) break;///没有增广路径了!
for(int i = sink; i != source; i = pre[i])
{
flow[pre[i]][i] += d[sink];
flow[i][pre[i]] -= d[sink];
}
}
t = ;///当做网络流量
for(int i = ; i < n; i ++)
t += flow[source][i];
return t;
}
}ek; char s[];
//void init()
//{
// _cle(vis, 0);
// _cle(pre, 0);
// _cle(anc, 0);
// _cle(deg, 0);
// _cle(edge, 0);
//}
int main()
{
int n, m;
while(~sfi2(n, m))
{
//init();
_cle(edge, );
ek.init( * n);
repu(i, , m)
{
scanf("%s", s);
int x = , y = ;
if(s[] == ',')
{
x = s[] - '';
if(s[] == ')') y = s[] - '';
else y = (s[] - '') * + s[] - '';
}
else
{
x = (s[] - '') * + s[] - '';
if(s[] == ')') y = s[] - '';
else y = (s[] - '') * + s[] - '';
}
edge[x][y] = edge[y][x] = ;
//pfi2(x, y);
} //repu(i, 0, n) pfi2(i, deg[i]);
repu(i, , n) ek.addCap(i, i + n, ); repu(i, , n) repu(j, , n)
if(edge[i][j]) ek.addCap(i + n, j, inf); int minn = n, ans;
repu(i, , n) repu(j, , n)
{
ek.addCap(i, i + n, inf);
ek.addCap(j, j + n, inf);
ans = ek.solve(i, j);
ek.addCap(i, i + n, );
ek.addCap(j, j + n, );
//pfi(ans);
minn = min(ans, minn);
}
pfi(minn);
}
return ;
}
uva 1660 & poj 1966(点连通度)的更多相关文章
- UVa 1660 电视网络(点连通度+最小割最大流+Dinic)
https://vjudge.net/problem/UVA-1660 题意:给出一个无向图,求出点连通度.即最少删除多少个点,使得图不连通. 思路: 如果求线连通度的话,直接求个最大流就可以了.但这 ...
- 括号序列问题 uva 1626 poj 1141【区间dp】
首先考虑下面的问题:Code[VS] 3657 我们用以下规则定义一个合法的括号序列: (1)空序列是合法的 (2)假如S是一个合法的序列,则 (S) 和[S]都是合法的 (3)假如A 和 B 都是合 ...
- poj 1966(求点连通度,边连通度的一类方法)
题目链接:http://poj.org/problem?id=1966 思路:从网上找了一下大牛对于这类问题的总结:图的连通度问题是指:在图中删去部分元素(点或边),使得图中指定的两个点s和t不连通 ...
- POJ 1966 Cable TV Network (无向图点连通度)
[题意]给出一个由n个点,m条边组成的无向图.求最少去掉多少点才能使得图中存在两点,它们之间不连通. [思路]回想一下s->t的最小点割,就是去掉多少个点能使得s.t不连通.那么求点连通度就枚举 ...
- UVA 1660 Cable TV Network 电视网络(无向图,点连通度,最大流)
题意:给一个无向图,求其点连通度?(注意输入问题) 思路: 如果只有1个点,那么输出“1”: 如果有0条边,那么输出“0”: 其他情况:用最大流解决.下面讲如何建图: 图的连通度问题是指:在图中删去部 ...
- POJ 1966 Cable TV Network (点连通度)【最小割】
<题目链接> 题目大意: 给定一个无向图,求点连通度,即最少去掉多少个点使得图不连通. 解题分析: 解决点连通度和边连通度的一类方法总结见 >>> 本题是求点连通度, ...
- POJ - 1966 Cable TV Network (最大流求点连通度)
题意:求一个无向图的点连通度.点联通度是指,一张图最少删掉几个点使该图不连通:若本身是非连通图,则点连通度为0. 分析:无向图的点连通度可以转化为最大流解决.方法是:1.任意选择一个点作为源点:2.枚 ...
- POJ 1966 求无向图点连通度
思路: n^2枚举(必须要n^2枚举啊)+拆点 特此嘲讽网上诸多垃圾题解,你们许多都是错的 -yyh //By SiriusRen #include <queue> #include &l ...
- UVA 820 --- POJ 1273 最大流
找了好久这两个的区别...UVA820 WA了 好多次.不过以后就做模板了,可以求任意两点之间的最大流. UVA 是无向图,因此可能有重边,POJ 1273是有向图,而且是单源点求最大流,因此改模板的 ...
随机推荐
- ios检测是否有网络
/** AFNetworkReachabilityStatusUnknown = -1, // 未知 AFNetworkReachabilityStatusNotReachable ...
- Android -- 自定义View小Demo,绘制四位数随机码(一)
1,现在有这样一个需求,实现显示随机随机数可能在代码中直接很简单的就实现了,但是现在我们直接自定义View来实现这个效果,那么我们来分析一波吧,我们允许开发者自己设置这个textview的大小,颜色, ...
- 关于在archlinux中安装virtualbox
之前安装的时候具体忘记了,现在重新整理一下安装的过程: 1. 安装virtualbox sudo pacman -S virtualbox 安装的过程中因依赖,需要安装提供host模块的包,这里我们安 ...
- mysql时间格式DATE_FORMAT()
1.以下是mysql查询中用到的时间格式的转化形式例子:SELECT DATE_FORMAT(NOW(),'%Y-%m-%d') -- 2015-10-28 SELECT DATE_FORMAT(NO ...
- javascript编程: JSON, Mapping, 回调
使用 Javascript 编程, 组合使用 JSON 数据格式,Mapping 和回调技术, 可以产生很强的表达效果. 在实际工作中, 总会有数据汇总的需求. 比如说, 取得了多个 device ...
- XML标签
SQL标签库提供了创建和操作XML文档的标签. 引入语法:<%@ taglib prefix="x" uri="http://java.sun.com/jsp/js ...
- SpringMVC 手动控制事务提交
描述 事务还是一个比较好的东东,有了这个,我们在做流程性的东西的时候,就会很好,很nice. 现在看看 SpringMVC 如何实现的,详细请看代码: 1.配置文件 applicationContex ...
- dynamics_cast<>
#include <iostream> class A { public: A(){} ~A(){} ;} }; class B:public A { public: B(){} ~B() ...
- Response.Clear()和Response.ClearContent()区别
Response.Clear()方法 Clear方法删除所有缓存中的HTML输出.但此方法只删除Response显示输入信息,不删除Response头信息. Response.ClearContent ...
- 微信小程序注册页面
Page Page() 函数用来注册一个页面.接受一个 object 参数,其指定页面的初始数据.生命周期函数.事件处理函数等. object 参数说明: 属性 类型 描述 data Object 页 ...