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是有向图,而且是单源点求最大流,因此改模板的 ...
随机推荐
- cxf client在后台不通且chunk设置为false的时候不能在控制台输出请求日志
场景: 服务编排框架支持编排webservice服务.call webservice的client是基于cxf做的.为了使用服务编排的开发者调试与定位问题方便,需要将webservice的请求与响应报 ...
- MVC HtmlHelper用法(一)@Html.BeginForm的使用总结
1.@using(Html.BeginForm()){} //提交到当前页面 2.@using ...
- 0512 Scrum 4.0
看板设计 每日例会时间定于下午放学回到宿舍,地点是在宿舍外的走廊或宿舍里,特殊情况待定: 团队开会照片 任务认领: 首页设计-------王俊杰 鸡汤版面-------列志华 论“汤”版面------ ...
- 数据库中 关于不能用in 不能用exist 等关键字 查询不出现字段的问题
这是之前在网上见到的一道题,后来心里略微想了想 觉得应该可能,所以就一闪而过了,之前去面试晨光的时候面试者问了我这道问题,当时也只是把自己的想法说了一下,可能因为当时面试的感觉不太好,面试官也没有追究 ...
- Bug测试报告--在线考试系统--金州勇士
项目名:在线考试系统 组名:金州勇士 测试者:宫丽君(nice!团队) 代码地址: ssh:git@git.coding.net:handsomeman/examm.git https://g ...
- Signalr简单例子
一.需要引用的 Js: 二.编码 用的是signalr2,需要新建Startup.cs类,编码如下: using Microsoft.Owin; using Owin; using System; u ...
- Css Study - Top Menu in Header 横向间隔的菜单
.shortcut ul li { display: inline; } CSS <style> ol, ul { list-style: none; } html, body, ul, ...
- Dynamics AX 2012 R2 为运行失败的批处理任务设置预警
我们主要有两种类型的系统监视:环境健康监视和性能监视. 环境健康监视一般对系统性能影响非常小,是为了提醒潜在的问题. 性能监视通常更有侵入性.监视期间,添加一个负载到环境.因此,它可以回答特定的问题或 ...
- php curl的使用
我们来采集一个页面,通常情况下,我们会使用file_get_contents()函数来获取: <?php $str = file_get_contents('http://www.baidu.c ...
- Date类型,Boolean类型,Number类型
1.Date类型: 1)创建Date对象: var date=new Date(); //Date对象会把当前日期和时间保存为其初始值 2)Date对象的方法: --这些得到的都是数字 ...