poj1966 求顶点连通度
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 4563 | Accepted: 2118 |
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
1
3
0
2
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define INF 1<<30
#define MOD 1000000007
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define pi acos(-1.0)
using namespace std;
const int MAXN = ;
struct node{
int to;
int val;
int next;
}edge[MAXN*MAXN],edge2[MAXN*MAXN];
int pre[MAXN],vis[MAXN],ind,n,m,S,T;
void add(int x,int y,int z){
edge2[ind].to = y;
edge2[ind].val = z;
edge2[ind].next = pre[x];
pre[x] = ind ++;
}
bool bfs(int S,int T){
memset(vis,-,sizeof(vis));
queue<int>q;
vis[S] = ;
q.push(S);
while(!q.empty()){
int tp = q.front();
q.pop();
for(int i = pre[tp]; i != -; i = edge[i].next){
int t = edge[i].to;
if(vis[t] == - && edge[i].val){
vis[t] = vis[tp] + ;
q.push(t);
}
}
}
return vis[T] != -;
}
int dfs(int rt,int low){
if(rt == T){
return low;
}
int used = ;
for(int i = pre[rt]; i != - && used < low; i = edge[i].next){
int t = edge[i].to;
if(vis[t] == vis[rt] + && edge[i].val){
int b = dfs(t,min(low-used,edge[i].val));
used += b;
edge[i].val -= b;
edge[i^].val += b;
}
}
if(used == )vis[rt] = -;
return used;
}
int dinic(int S,int T){
int ans = ;
while(bfs(S,T)){
while(){
int a = dfs(S,INF);
if(a == )break;
ans += a;
}
}
return ans;
}
int main(){
while(~scanf("%d%d",&n,&m)){
if(m == ){
if(n == )
printf("1\n");
else
printf("0\n");
continue;
}
ind = ;
memset(pre,-,sizeof(pre));
for(int i = ; i <= m; i++){
int x,y;
scanf(" (%d,%d)",&x,&y);
x ++,y ++;
add(x+n,y,INF),add(y,x+n,);
add(y+n,x,INF),add(x,y+n,);
}
for(int i = ; i <= n; i++){
add(i,i+n,),add(i+n,i,);
}
int ans = INF;
for(int i = ; i <= n; i++){
for(int j = ; j < ind; j++){
edge[j] = edge2[j];
}
S = + n,T = i;
ans = min(ans,dinic(S,T));
}
if(ans == INF)ans = n;
printf("%d\n",ans);
}
return ;
}
poj1966 求顶点连通度的更多相关文章
- poj 1966(顶点连通度)
题意:给出一个n个节点和m条边的图,求该图的顶点连通度. 分析: 顶点连通度的求解可以转换为网络最大流问题. (1)原图G中的每个顶点v变成网络中的两个顶点v‘和v’‘,顶点v’至v''有一个条弧(有 ...
- POJ--1966--Cable TV Network【无向图顶点连通度】
链接:http://poj.org/problem?id=1966 题意:一个无向图,n个点,m条边,求此图的顶点连通度. 思路:顶点连通度,即最小割点集里的割点数目.一般求无向图顶点连通度的方法是转 ...
- Cable TV Network 顶点连通度 (最大流算法)
Cable TV Network 题目抽象:给出含有n个点顶点的无向图,给出m条边.求定点联通度 K 算法:将每个顶点v拆成 v' v'' ,v'-->v''的容量为1. ...
- Algorithm --> 树中求顶点A和B共同祖先
树中求顶点A和B共同祖先 题目: 给定一颗树,以及两个顶点A和B,求最近的共同祖先,和包含的子顶点个数? 比如:给定如下图的树,以及顶点13和8,则共同祖先为3,以3为root的子顶点共有8个
- POJ 1966 Cable TV Network(顶点连通度的求解)
Cable TV Network Time Limit: 1000MS Memory Limit: 30000K Total Submissi ...
- poj 1966 Cable TV Network 顶点连通度
题目链接 给一个图, n个点m条边, 求至少去掉多少个点可以使得图不再联通.随便指定一个点为源点, 枚举其他点为汇点的情况, 跑网络流, 求其中最小的情况. 如果最后ans为inf, 说明是一个完全图 ...
- osg shader 相机观察矩阵逆矩阵 求顶点世界坐标
uniform mat4 osg_ViewMatrixInverse;//osg内置uniform void main() { vec4 posWorld = osg_ViewMatrixInvers ...
- poj1815Friendship(最小割求割边)
链接 题意为去掉多少个顶点使图不连通,求顶点连通度问题.拆点,构造图,对于<u,v>可以变成<u2,v1> <v2,u1>容量为无穷,<u1,u2>容量 ...
- 求割点模板(可求出割点数目及每个割点分割几个区域)POJ1966(Cable TV Network)
题目链接:传送门 题目大意:给你一副无向图,求解图的顶点连通度 题目思路:模板(图论算法理论,实现及应用 P396) Menger定理:无向图G的顶点连通度k(G)和顶点间最大独立轨数目之间存在如下关 ...
随机推荐
- [No00003E]26个字母暗藏的单词秘密
个字母暗藏的单词秘密 人们普通认为:英语是拼音文字,因而与象形无关.但是,实际上,即使作为拼音文字,其字母的来源也与象形有关.根据笔者十多年的研究结果,英语中的二十六个字母每个字母都有其象形意义,而且 ...
- 转:软件架构入门 (from 阮一峰)
说明:其中讲到了 5 种的架构模型,很不错. from: http://www.ruanyifeng.com/blog/2016/09/software-architecture.html
- There was an internal API error.的解决办法
1.当安装应用到4s时,偶尔有些程序会报这个错误,There was an internal API error 解决办法如下: 真机运行下,项目在iOS8.0下运行正常,但是一旦换到iOS7.0和7 ...
- iOS中NSScanner 的用法
NSScanner是一个类,用于在字符串中扫描指定的字符,尤其是把它们翻译/转换为数字和别的字符串.可以创建NSScanner时制定他的String属性,然后scanner会按照你的要求从头到尾扫描这 ...
- Hash链表
<?php /* +------------------------------------------------------------------------------ | dateti ...
- UDP的坏处
众所周知,UDP是一个面向无连接的协议.通信时不可靠的.这就会出现一些问题 (1)数据报丢失 因为是无连接,的所以可以用recvfrom和sendto来接收和发送消息,如果socket是阻塞的,那么当 ...
- 【转】如何拿到半数面试公司Offer——我的Python求职之路
原文地址 从八月底开始找工作,短短的一星期多一些,面试了9家公司,拿到5份Offer,可能是因为我所面试的公司都是些创业性的公司吧,不过还是感触良多,因为学习Python的时间还很短,没想到还算比较容 ...
- C# WebApi Xml序列化问题解决方法:“ObjectContent`1”类型未能序列化内容类型“application/xml;charset=utf-8"的响应正文。...
在调试一个WebApi程序时,出现下面错误: 通过分析怀疑是未添加序列化属性引起的,实体类改为下面结构后,问题依旧: 通过查阅资料和不断尝试,修改实体类的属性注解搞定:
- ThreadLocal原理及其实际应用
前言 java猿在面试中,经常会被问到1个问题: java实现同步有哪几种方式? 大家一般都会回答使用synchronized, 那么还有其他方式吗? 答案是肯定的, 另外一种方式也就是本文要说的Th ...
- 【前端也要学点算法】 归并排序的JavaScript实现
前文我们了解了快速排序算法的实现,本文我们来了解下另一种流行的排序算法-归并排序算法. 我们先来回顾下快排.快排的核心是找出一个基准元素,把数组中比该元素小的放到左边数组,比该元素大的放到右边数组,如 ...