1797: [Ahoi2009]Mincut 最小割
来源:互联网 发布:如何利用淘宝赚钱 编辑:程序博客网 时间:2024/06/03 06:13
题目链接
题目大意:给出一个有向图,每条边有流量,给出源点汇点s、t。对于每条边,询问:(1)是否存在一个最小割包含该边(2)是否所有的最小割都包含该边
题解:套路题……知道结论就好了
我的收获:套路++
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <stack>using namespace std;const int N=4005;const int M=120005;const int INF=1e9;int n,m,st,ed;int t,head[N],last[N];int num[N],d[N];int scnt,col[N];int tim,dfn[N],low[N];bool Exit,ins[N];stack<int> s;struct edge{int fro,to,c,nex;}e[M*2];void add(int u,int v,int w){e[t]=(edge){u,v,w,head[u]};last[u]=head[u]=t++;}void insert(int x,int y,int z){add(x,y,z),add(y,x,0);};int dfs(int x,int in){ if(x==ed) return in; int ans=0,f; for(int i=last[x];i!=-1;last[x]=i=e[i].nex) { int v=e[i].to; if(e[i].c&&d[v]==d[x]-1){ f=dfs(v,min(in-ans,e[i].c)); ans+=f;e[i].c-=f;e[i^1].c+=f; if(Exit||ans==in) return ans; } } if(--num[d[x]]==0) Exit=1;//GAP优化 d[x]++,num[d[x]]++,last[x]=head[x]; return ans;}void tarjan(int x){ int now=0; dfn[x]=low[x]=++tim; s.push(x);ins[x]=1; for(int i=head[x];i!=-1;i=e[i].nex){ int v=e[i].to; if(!e[i].c) continue; if(!dfn[v]) tarjan(v),low[x]=min(low[x],low[v]); else if(ins[v]) low[x]=min(low[x],dfn[v]); } if(low[x]==dfn[x]){ scnt++; while(x!=now){ now=s.top();s.pop(); ins[now]=0;col[now]=scnt; } }}void Isap(){ Exit=0; while(!Exit) dfs(st,INF);}void work(){ Isap(); for(int i=1;i<=n;i++) if(!dfn[i]) tarjan(i); for(int i=0;i<t;i+=2){ putchar((!e[i].c&&col[e[i].fro]!=col[e[i].to])?'1':'0'); putchar(' '); putchar((!e[i].c&&col[st]==col[e[i].fro]&&col[ed]==col[e[i].to])?'1':'0'); putchar('\n'); } }void init(){ memset(head,-1,sizeof(head)); memset(last,-1,sizeof(last)); cin>>n>>m>>st>>ed;num[0]=n; for(int x,y,z,i=1;i<=m;i++) scanf("%d%d%d",&x,&y,&z),insert(x,y,z);}int main(){ init(); work(); return 0;}
阅读全文
0 0
- 1797: [Ahoi2009]Mincut 最小割
- 1797: [Ahoi2009]Mincut 最小割
- 1797: [Ahoi2009]Mincut 最小割
- 1797: [Ahoi2009]Mincut 最小割
- [Ahoi2009]Mincut 最小割
- bzoj 1797: [Ahoi2009]Mincut 最小割
- 【BZOJ 1797】 [Ahoi2009]Mincut 最小割
- BZOJ 1797 [Ahoi2009]Mincut 最小割
- 1797: [Ahoi2009]Mincut 最小割(from hzwer)
- bzoj 1797: [Ahoi2009]Mincut 最小割
- 1797: [Ahoi2009]Mincut 最小割 最小割+tarjan
- bzoj 1797: [Ahoi2009]Mincut 最小割 (最小割+tarjan)
- BZOJ1797: [Ahoi2009]Mincut 最小割
- BZOJ1797: [Ahoi2009]Mincut 最小割
- BZOJ1797: [Ahoi2009]Mincut 最小割
- bzoj1797: [Ahoi2009]Mincut 最小割
- 【bzoj1797】[Ahoi2009]Mincut 最小割
- bzoj1797: [Ahoi2009]Mincut 最小割
- Code+ 2017年12月月赛练习题 晨跑
- 二叉树遍历的非递归Java实现
- powerDesigner绘制类图
- Android中的自绘View的那些事儿(六)之 画布裁剪
- Android-x86 Porting Guide for OPENTHOS Developers
- 1797: [Ahoi2009]Mincut 最小割
- form传递值后台为空
- 测试用例编写设计
- rplidar 使用
- 世界国家中英文对照
- 自学编程需要注意什么?
- xml透明度参照表
- Windows下安装使用curl命令
- google play billing library 文档备查