博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
No.36 - POJ1966 图的联通度-枚举T网络流
阅读量:4060 次
发布时间:2019-05-25

本文共 1349 字,大约阅读时间需要 4 分钟。

求一个图的联通度,就是找图中固定源点,然后枚举汇点求最小割。

然后最小割中最小的一个就是图的联通度。

#include
#include
#include
#include
#include
#include
#define MM(x,y) memset(x,y,sizeof(x))#define INF 0x3f3f3f3f#define LL long longusing namespace std;/* ShellDawn POJ1966 No.36 */#define maxn 55int N,M;int S,T;struct Edge{ int to; int v; int rvs; int pre;};Edge E[maxn*maxn*4];int pre[maxn*2];int cnt;int In[maxn*maxn][2];int V[maxn*2];void addE(int a,int b,int v){ E[cnt].to = b; E[cnt].v = v; E[cnt].rvs = cnt+1; E[cnt].pre = pre[a]; pre[a] = cnt++; E[cnt].to = a; E[cnt].v = 0; E[cnt].rvs = cnt - 1; E[cnt].pre = pre[b]; pre[b] = cnt ++;}bool BFS(int s){ MM(V,0); queue
q; q.push(s); V[s] = 1; while(!q.empty()){ int now = q.front(); q.pop(); for(int i=pre[now];i!=0;i=E[i].pre){ if(E[i].v > 0 && V[E[i].to] == 0){ V[E[i].to] = V[now] + 1; q.push(E[i].to); } } } if(V[T] > 0) return true; return false;}int DFS(int now,int minflow){ if(now == T) return minflow; int flow = 0; for(int i=pre[now];i!=0 && minflow; i = E[i].pre){ if(E[i].v > 0 && V[E[i].to] == V[now] + 1){ int f = DFS(E[i].to,min(minflow,E[i].v)); flow += f; minflow -= f; E[i].v -= f; E[E[i].rvs].v += f; } } if(flow == 0) V[now] = 0; return flow;}void build(){ MM(pre,0); cnt = 1; for(int i=0;i
1){printf("0\n");continue;} for(int i=0;i
=INF?N:ans); } return 0;}

转载地址:http://tnwji.baihongyu.com/

你可能感兴趣的文章
Mac环境下svn的使用
查看>>
github简单使用教程
查看>>
如何高效利用GitHub
查看>>
环境分支-git版本管理
查看>>
uni-app 全局变量
查看>>
js判断空对象的几种方法
查看>>
java 不用递归写tree
查看>>
springboot2 集成Hibernate JPA 用 声明式事物
查看>>
fhs-framework jetcache 缓存维护之自动清除缓存
查看>>
SpringBoot 动态编译 JAVA class 解决 jar in jar 的依赖问题
查看>>
fhs-framework springboot mybatis 解决表关联查询问题的关键方案-翻译服务
查看>>
ZUUL2 使用场景
查看>>
Spring AOP + Redis + 注解实现redis 分布式锁
查看>>
elastic-job 和springboot 集成干货
查看>>
php开发微服务注册到eureka中(使用sidecar)
查看>>
mybatis mybatis plus mybatis jpa hibernate spring data jpa比较
查看>>
支付宝生活号服务号 用户信息获取 oauth2 登录对接 springboot java
查看>>
CodeForces #196(Div. 2) 337D Book of Evil (树形dp)
查看>>
uva 12260 - Free Goodies (dp,贪心 | 好题)
查看>>
uva-1427 Parade (单调队列优化dp)
查看>>