HDU-3987 Harry Potter and the Forbidden Forest(最大流)
来源:互联网 发布:宏杰加密软件 编辑:程序博客网 时间:2024/06/04 07:15
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3987
题意:求边数最少的割集
思路:与上文一样
代码:
#include<bits/stdc++.h>using namespace std;typedef long long ll;const ll INF = 1e18;const int N = 500005;int n,m,s,t,tot;int head[N],dep[N],cur[N];struct edge{ int to,nxt; ll cap; edge(int t = 0,int n = 0,ll c = 0):to(t),nxt(n),cap(c){}}E[N];void init(){ memset(head,-1,sizeof(head)); tot = 0;}void add(int u,int v,ll cap){ E[tot] = edge(v,head[u],cap); head[u] = tot++;}bool bfs(int s,int t){ memset(dep,-1,sizeof(dep)); queue<int> q; dep[s] = 0; q.push(s); while(!q.empty()) { int u = q.front();q.pop(); for(int i = head[u];~i;i = E[i].nxt) { int v = E[i].to; if(E[i].cap > 0 && dep[v] == -1) { dep[v] = dep[u] + 1; q.push(v); } } } return dep[t] != -1;}ll dfs(int u,ll flow){ if(u == t) return flow; ll w ,used = 0; for(int i = head[u];~i;i = E[i].nxt) { int v = E[i].to; if(dep[v] == dep[u]+1) { w = flow - used; w = dfs(v,min(w,E[i].cap)); E[i].cap -= w; E[i^1].cap += w; if(v) cur[u] = i; used += w; if(used == flow) return flow; } } if(!used) dep[u] = -1; return used;}ll dinic(int s,int t){ ll res = 0; while(bfs(s,t)) { for(int i = 1;i <= t;i++) cur[i] = head[i]; res += dfs(s,INF); } return res;}int main(){ int T; scanf("%d",&T); for(int ca = 1;ca <= T;ca++) { init(); scanf("%d%d",&n,&m); s = 1,t = n; int u,v,d; ll w; while(m--) { scanf("%d%d%lld%d",&u,&v,&w,&d); ++u;++v; add(u,v,w*1000000+1); if(d) add(v,u,w*1000000+1); else add(v,u,0); } printf("Case %d: %lld\n",ca,dinic(s,t)%1000000); } return 0;}
阅读全文
0 0
- HDU-3987 Harry Potter and the Forbidden Forest(最大流)
- HDU 3987 Harry Potter and the Forbidden Forest 最小割
- hdu 3987 Harry Potter and the Forbidden Forest
- hdu 3987 Harry Potter and the Forbidden Forest
- 【HDU】3987 Harry Potter and the Forbidden Forest 最小割
- 【最小割】HDU 3987 Harry Potter and the Forbidden Forest
- hdu 3987 Harry Potter and the Forbidden Forest 最小割
- HDU 3987 Harry Potter and the Forbidden Forest
- hdu 3987 Harry Potter and the Forbidden Forest
- HDU 3987 Harry Potter and the Forbidden Forest
- hdu 3987 Harry Potter and the Forbidden Forest【网路流最小割模型】
- HDU 3987 Harry Potter and the Forbidden Forest(最小割中的最少割边)经典
- hdu 3987 Harry Potter and the Forbidden Forest (最小割)
- HDU 3987 Harry Potter and the Forbidden Forest(最小割的最少割边数)
- HDU3987 Harry Potter and the Forbidden Forest(最小割)
- HDU3987:Harry Potter and the Forbidden Forest(最小割边数)
- HDU--3987[Harry Potter and the Forbidden Forest] 求最小割集中的最小边数
- hdu 3987 Harry Potter and the Forbidden Forest 求割边最少的最小割
- LG1073【NOIp2009】最优贸易 <Tarjan+DP>
- 为什么买回500G的硬盘,实际可用空间不是500G
- 利用docker配置MySQL主从
- 1135. Is It A Red-Black Tree (30)
- 剑指Offer--13.调整数组顺序使奇数位于偶数前面
- HDU-3987 Harry Potter and the Forbidden Forest(最大流)
- Windows三种文件系统:NTFS、FAT32、FAT16的区别
- 织梦如何转换编码格式
- Camera-IMU标定过程
- 欢迎使用CSDN-markdown编辑器
- 树链剖分初讲 && [bzoj1036][ZJOI2008]树的统计Count
- JAVA,网页流行语言JAVA,介绍JAVA。
- 【iOS界面开发】UIWindow屏幕旋转自适应
- babel到底将代码转换成什么鸟样?