文章标题 HDU 4280 :Island Transport (最大流--ISAP)
来源:互联网 发布:c语言的位域 编辑:程序博客网 时间:2024/06/02 07:04
题目链接
一开始用的dinic 发现T了,然后换了个IS AP的模板
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <queue>#include <set>#include <map>#include <algorithm>#include <math.h>#include <vector>using namespace std;typedef long long ll;const int mod=1e9+7;const int maxn=1e5+10;const int inf=0x3f3f3f3f;const int maxm=1000006;struct Edge{ int to,nex,cap,flow;};struct ISAP{ Edge edge[maxm]; int tol; int head[maxn]; int gap[maxn],dep[maxn],cur[maxn]; int n,m; void init() { tol=0; memset(head,-1,sizeof(head)); } void addedge(int u,int v,int w,int rw=0) { edge[tol].to=v; edge[tol].cap=w; edge[tol].flow=0; edge[tol].nex=head[u]; head[u]=tol++; edge[tol].to=u; edge[tol].cap=rw; edge[tol].flow=0; edge[tol].nex=head[v]; head[v]=tol++; } int Q[maxn]; void BFS(int start,int end) { memset(dep,-1,sizeof(dep)); memset(gap,0,sizeof(gap)); gap[0]=1; int front=0, rear=0; dep[end]=0; Q[rear++]=end; while(front!=rear){ int u=Q[front++]; for(int i=head[u];i!=-1;i=edge[i].nex){ int v=edge[i].to; if(dep[v]!=-1)continue; Q[rear++]=v; dep[v]=dep[u]+1; gap[dep[v]]++; } } } int S[maxn]; int sap(int start,int end,int n) { BFS(start,end); memcpy(cur,head,sizeof(head)); int top=0; int u=start; int ans=0; while(dep[start]<n) { if(u==end) { int Min=inf; int inser; for(int i=0;i<top;i++) if(Min>edge[S[i]].cap-edge[S[i]].flow) { Min=edge[S[i]].cap-edge[S[i]].flow; inser=i; } for(int i=0;i<top;i++) { edge[S[i]].flow+=Min; edge[S[i]^1].flow-=Min; } ans+=Min; top=inser; u=edge[S[top]^1].to; continue; } bool flag=false; int v; for(int i=cur[u];i!=-1;i=edge[i].nex) { v=edge[i].to; if(edge[i].cap-edge[i].flow&&dep[v]+1==dep[u]) { flag=true; cur[u]=i; break; } } if(flag){ S[top++]=cur[u]; u=v; continue; } int Min=n; for(int i=head[u];i!=-1;i=edge[i].nex) if(edge[i].cap-edge[i].flow&&dep[edge[i].to]<Min) { Min=dep[edge[i].to]; cur[u]=i; } gap[dep[u]]--; if(!gap[dep[u]])return ans; dep[u]=Min+1; gap[dep[u]]++; if(u!=start)u=edge[S[--top]^1].to; } return ans; }}isap;int N,M;struct point { int x,y;}p[maxn];int main(){ int T; scanf ("%d",&T); while (T--){ scanf ("%d%d",&N,&M); isap.init(); for (int i=1;i<=N;i++){ scanf ("%d%d",&p[i].x,&p[i].y); } int u,v,c; for (int i=1;i<=M;i++){ scanf ("%d%d%d",&u,&v,&c); isap.addedge(u,v,c); isap.addedge(v,u,c); } int st=1,ed=1; for (int i=2;i<=N;i++){ if (p[st].x>p[i].x)st=i; if (p[ed].x<p[i].x)ed=i; } int ans=isap.sap(st,ed,N); printf ("%d\n",ans); } return 0;}
阅读全文
0 0
- 文章标题 HDU 4280 :Island Transport (最大流--ISAP)
- HDU - 4280 Island Transport(ISAP)
- HDU -- 4280 Island Transport(最大流)
- hdu 4280 Island Transport(最大流)
- Hdu 4280 Island Transport(最大流)
- hdu 4280 Island Transport (最大流)
- HDU 4280 Island Transport (最大流)
- HDU 4280 Island Transport(最大流)
- hdu4280 Island Transport (最大流ISAP算法)
- hdu 4280 Island Transport 【图论-网络流-ISAP+栈优化】
- hdu 4280 Island Transport isap果题
- HDU 4280 Island Transport 最大流SAP
- hdu 4280 Island Transport (最大流)
- hdu 4280 Island Transport 最大流sap
- HDU 4280 Island Transport 最大流+sap
- HDU 4280Island Transport(裸最大流)
- HDU 4280Island Transport(网络流之最大流)
- Island Transport hdu 4280 (最大流 dinic)
- soj3360_完全背包
- python 笔记(2)
- Vegas项目归档功能怎么使用?
- struts2之路径问题
- Python小工具——通过API获取天气预报
- 文章标题 HDU 4280 :Island Transport (最大流--ISAP)
- RecyclerView 拖动/滑动多选的实现(3)
- 12 聚集函数:avg() count() max() min() sum()
- 字符串匹配问题——KMP算法理论
- Invitation Cards POJ
- 可视化工具--D3--案例分析--Histogram Chart
- web开发时浏览器兼容性问题汇总
- MonkeyRunner“不是内部或外部命令”解决办法
- 剑指offer_重建二叉树