hihocode#1378 : 网络流二·最大流最小割定理(最大流求最小割集)
来源:互联网 发布:rar解压软件for mac 编辑:程序博客网 时间:2024/05/19 05:02
题目链接
EK求最小割集模板
代码:
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<string>#include<vector>#include<stack>#include<bitset>#include<cstdlib>#include<cmath>#include<set>#include<list>#include<deque>#include<map>#include<queue>using namespace std;typedef long long ll;const double PI = acos(-1.0);const double eps = 1e-6;const int INF = 1000000000;const int maxn = 123456;int T,n,m;int tot,s,t;int head[maxn],vis[maxn],path[maxn];set<int>st;struct EDGE{ int from,to; int cap,flow; int next;}e[maxn];void init(){ tot=0; s=1; t=n; memset(head,-1,sizeof(head)); memset(vis,0,sizeof(vis)); memset(path,0,sizeof(path));}void add_edge(int u,int v,int w){ e[tot].from=u; e[tot].to=v; e[tot].cap=w; e[tot].flow=0; e[tot].next=head[u]; head[u]=tot++;}int bfs(){ queue<int>q; q.push(s); vis[s]=1; path[s]=-1; while(!q.empty()) { int u=q.front(); q.pop(); for(int i=head[u];i!=-1;i=e[i].next) { int v=e[i].to; if(e[i].cap-e[i].flow>0&&!vis[v]) { path[v]=i; vis[v]=1; if(v==t) return 1; q.push(v); } } } return 0;}int EK(){ int maxFlow=0; int flow,i; while(bfs()) { memset(vis,0,sizeof(vis)); i=path[t]; flow=INF; while(i!=-1) { flow=min(flow,e[i].cap-e[i].flow); i=path[e[i].from]; } i=path[t]; while(i!=-1) { e[i].flow+=flow; e[i^1].flow-=flow; i=path[e[i].from]; } maxFlow+=flow; } return maxFlow;}void Get_set()//求割集{ memset(vis,0,sizeof(vis)); queue<int>q; q.push(1); vis[1]=1; while(!q.empty()) { int u=q.front(); q.pop(); st.insert(u); for(int i=head[u];i!=-1;i=e[i].next) { int v=e[i].to; if(vis[v]==0&&e[i].cap-e[i].flow>0) { vis[v]=1; q.push(v); } } }}int main(){ while(scanf("%d%d",&n,&m)!=EOF) { init(); for(int i=0;i<m;i++) { int u,v,c; scanf("%d%d%d",&u,&v,&c); add_edge(u,v,c); add_edge(v,u,0); } int maxFlow=EK(); Get_set(); printf("%d %d\n",maxFlow,st.size()); for(set<int>::iterator it = st.begin();it!=st.end();it++) { if(it!=st.begin()) printf(" "); printf("%d",*it); } printf("\n"); } return 0;}
阅读全文
0 0
- hihocode#1378 : 网络流二·最大流最小割定理(最大流求最小割集)
- 网络流二·最大流最小割定理
- hihocoder 网络流二·最大流最小割定理
- 网络流二·最大流最小割定理 HihoCoder
- 网络流 最小割最大流定理
- 网络的最大流最小割定理
- 最大流最小割定理
- 最大流最小割定理
- 最大流最小割定理
- 最大流最小割定理
- 最大流-最小割定理
- 最大流最小割定理
- 最大流最小割定理
- 最小割最大流定理
- hihocoder 1378 : 网络流二·最大流最小割定理
- hihocoder 1378 网络流二·最大流最小割定理
- hiho一下 #1378 : 网络流二·最大流最小割定理 【最大流及S集合】
- 最大流/最小割
- 观察者模式android版
- bzoj 4818: [Sdoi2017]序列计数(DP+矩阵快速幂)
- 网络学习
- 集合的实现1--使用对象
- Python中的with语法与上下文管理器
- hihocode#1378 : 网络流二·最大流最小割定理(最大流求最小割集)
- hdu 1002 Java
- C++基础知识三
- 轻而快的CAS
- struts2--类型转换
- Servlet中getRequestURI()和getRequestURL()方法的区别
- 关于私有继承和保护继承
- Latex
- Android Sms短信发送