Poj 1966 Cable TV Network【点连通度------最大流Dinic】
来源:互联网 发布:淘宝店招商 编辑:程序博客网 时间:2024/05/01 18:31
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
题目大意:
求点连通度,就是问最少去掉多少个点能够使得剩下的图不连通。
思路(学习摘抄自网络):
图的连通度分为点连通度和边连通度:
(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】)处理。
对应枚举源点S和汇点T,跑最大流,维护最小值即可。
如果最大流跑出来的值为INF,表示图是完全连通的,需要将所有点都去掉才行。
Ac代码:
#include<stdio.h>#include<string.h>#include<queue>#include<iostream>using namespace std;#define INF 0x3f3f3f3fstruct node{ int from; int to; int w; int next;}e[400000];int n,m,ss,tt,cont;int cur[4000];int divv[4000];int head[4000];int bian[40000][2];void add(int from,int to,int w){ e[cont].to=to; e[cont].w=w; e[cont].next=head[from]; head[from]=cont++;}void getmap(int sss,int ttt){ ss=sss; tt=ttt; cont=0; memset(head,-1,sizeof(head)); for(int i=0;i<n;i++) { add(i,i+n,1); add(i+n,i,0); } for(int i=0;i<m;i++) { int u=bian[i][0],v=bian[i][1]; add(u+n,v,INF); add(v,u+n,0); add(v+n,u,INF); add(u,v+n,0); }}int makedivv(){ queue<int >s; memset(divv,0,sizeof(divv)); divv[ss]=1; s.push(ss); while(!s.empty()) { int u=s.front(); if(u==tt)return 1; s.pop(); for(int i=head[u];i!=-1;i=e[i].next) { int v=e[i].to; int w=e[i].w; if(w&&divv[v]==0) { divv[v]=divv[u]+1; s.push(v); } } } return 0;}int Dfs(int u,int maxflow,int tt){ if(u==tt)return maxflow; int ret=0; for(int &i=cur[u];i!=-1;i=e[i].next) { int v=e[i].to; int w=e[i].w; if(w&&divv[v]==divv[u]+1) { int f=Dfs(v,min(maxflow-ret,w),tt); e[i].w-=f; e[i^1].w+=f; ret+=f; if(ret==maxflow)return ret; } } return ret;}int Slove(int sss,int ttt){ getmap(sss,ttt); int ans=0; while(makedivv()==1) { memcpy(cur,head,sizeof(head)); ans+=Dfs(ss,INF,tt); } return ans;}int main(){ while(~scanf("%d%d",&n,&m)) { if(m==0) { if(n==1)printf("1\n"); else printf("0\n"); continue; } if(n==0) { printf("0\n"); continue; } for(int i=0;i<m;i++) { int u,v; scanf(" (%d,%d)",&u,&v); bian[i][0]=u; bian[i][1]=v; } int output=INF; for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { int tmp=Slove(i+n,j); output=min(output,tmp); } } if(output>=n)output=n; printf("%d\n",output); }}
- Poj 1966 Cable TV Network【点连通度------最大流Dinic】
- POJ 1966--Cable TV Network 【求无向图的点连通度 构造最大流模型 && dinic】
- poj 1966 Cable TV Network 顶点连通度-最大流
- 【连通图|点连通度】POJ-1966 Cable TV Network
- 点连通度 边连通度 最大流最小割 最小割点集 最小割边集 & POJ 1966 Cable TV Network
- poj 1966 Cable TV Network 点连通度
- POJ1966 Cable TV Network 点连通度
- 【poj1966】Cable TV Network 无向图点连通度(最大流)
- Cable TV Network- POJ 1966 连通量
- POJ 1966 Cable TV Network 无向图的点连通度
- poj 1966 zoj 2182 Cable TV Network(无向图顶点连通度(sap求最大流))
- POJ 1966 Cable TV Network 顶点连通度的求解
- POJ 1966 / ZOJ 2182 : Cable TV Network - 顶点连通度
- POJ 1966 Cable TV Network(顶点连通度)
- poj 1966 Cable TV Network 点联通度
- pku 1966 Cable TV Network(求无向图的点连通度)
- POJ 1966 Cable TV Network
- poj 1966 Cable TV Network
- 函数调用约定与名字修饰约定
- ioctl命令构建
- spark 集群部署可用方法
- linux学习
- 排序算法(3)—优先队列,堆排序
- Poj 1966 Cable TV Network【点连通度------最大流Dinic】
- PHP中分隔符与连接符的效率对比
- Ubuntu下Tomcat8的安装与配置
- 编程之美读书笔记-1的数目
- theano学习指南--深度置信网络(DBN)(源码)
- 【NOIP提高】看电影
- 【Java基础】——HashMap设计原理&实现分析
- C++实现strcpy, strlen, strstr, atoi等字符串相关API
- 【poj3159】 Candies