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是有向图,而且是单源点求最大流,因此改模板的 ...
随机推荐
- android Thread和Service的区别
http://www.cnblogs.com/devinzhang/archive/2012/01/11/2319433.html (zhuan)
- html5 Web Storage(localStorage(),sessionStorage())
Web Storage包括了两种存储方式:sessionStorage和localStorage sessionStorage 是会话级别的存储,这些数据只有在同一个会话中的页面才能访问并且当会话结束 ...
- RSA算法基础详解
. 首页 博客园 联系我 前言:在RSA诞生之前. RSA算法. 质数与互质数. 模运算. 同余. 欧拉函数. 欧拉定理与模反元素. 真实的例子. 计算密钥. 密钥组成与加解密公式. 安全性. 一点感 ...
- Spring RabbitMq
spring-rabbitmq.xml文件内容如下: <?xml version="1.0" encoding="UTF-8"?><beans ...
- new一个数组,delete释放内存
int *a = new int[4]; for(int i=0;i<4;i++) { a[i] = i; printf("a[%d]=%d\n", i, i); } del ...
- metasploit模块功能介绍
metasploit的模块构成及功能分析 转载自----http://forum.cnsec.org/thread-94704-1-1.html 今天我们介绍一下metasploit的基础架构和 市 ...
- (转)awk实例练习(一)
文章转自 http://www.cnblogs.com/zhuyp1015/archive/2012/07/14/2591822.html 前一篇学习了awk的基本知识,现在来做一些练习加深一下印象. ...
- iOS 键盘
http://blog.sina.com.cn/s/blog_7018d3820101djut.html 一.键盘风格 UIKit框架支持8种风格键盘. typedef enum { UIKeyboa ...
- python中的@
一.函数修饰符 '@' 用做函数的修饰符,可以在模块或者类的定义层内对函数进行修饰, 出现在函数定义的前一行,不允许和函数定义在同一行 一个修饰符就是一个函数,它将被修饰的函数作为参数,并返回修饰后的 ...
- JDBC连接sql server数据库及其它
JDBC连接sql server数据库的步骤如下: 1.加载JDBC驱动程序: 在连接数据库之前,首先要加载想要连接的数据库的驱动到JVM(Java虚拟机), 这通过java.lang.Class类的 ...