USACO 4.2.1 网络流 最高标号预流推进(HLPP)
2016-02-18 16:49
597 查看
/* ID: shenxyy1 TASK: ditch LANG: C++11 */ #include<bits/stdc++.h> using namespace std; #define set(x) Set(x) #define REP(i,j,k) for (int i=(j),_end_=(k);i<=_end_;++i) #define DREP(i,j,k) for (int i=(j),_start_=(k);i>=_start_;--i) #define debug(...) fprintf(stderr,__VA_ARGS__) #define mp make_pair #define x first #define y second #define pb push_back #define SZ(x) (int((x).size()-1)) #define ALL(x) ((x).begin()+1),(x).end() template<typename T> inline bool chkmin(T &a,const T &b){ return a > b ? a = b, 1 : 0; } template<typename T> inline bool chkmax(T &a,const T &b){ return a < b ? a = b, 1 : 0; } typedef long long LL; typedef pair<int,int> node; const int dmax=1010,oo=0x3f3f3f3f; int n,m; int a[dmax][dmax] , ans; int d[dmax],e[dmax]; priority_queue <node> q; inline bool operator >(node a,node b){ return a.y>b.y; } bool p[dmax]; void Set(int x){ p[x]=1; } void unset(int x){ p[x]=0; } bool check(int x){ return x!=1 && x!=n && !p[x] && e[x]>0; } void preflow(){ e[1]=oo; d[1]=n-1; q.push(mp(1,n-1)); set(1); while (!q.empty()){ bool flag=1; int k=q.top().x; q.pop(),unset(k); DREP(i,n,1) if ((d[k]==d[i]+1 || k==1) && a[k][i]>0){ flag=0; int t=min(a[k][i],e[k]); e[k]-=t; a[k][i]-=t; e[i]+=t; a[i][k]+=t; if (check(i)){ q.push(mp(i,d[i])); set(i); } if (e[k]==0) break; } if (flag){ d[k]=oo; REP(i,1,n) if (a[k][i]>0) chkmin(d[k],d[i]+1); } if (check(k)){ q.push(mp(k,d[k])); set(k); } } ans=e ; } int main(){ freopen("ditch.in","r",stdin); freopen("ditch.out","w",stdout); scanf("%d%d",&m,&n); REP(i,1,m){ int x,y,z; scanf("%d%d%d",&x,&y,&z); a[x][y]+=z; } preflow(); printf("%d\n",ans); return 0; }
相关文章推荐
- PeopleRank从社交网络中发现个体价值
- 【网络流24题】搭配飞行员/飞行员配对方案
- HttpServletResponse
- socket http tcp 等
- iOS9 Xcode7 https解决方法
- 博客新地址 http://blog.devtao.com
- Socket Http
- TCP/IP协议详解学习笔记-- 链路层(包含CentOS6.5下抓包工具tcpdump的使用)
- [神经网络]1.4-Using neural nets to recognize handwritten digits-A simple network to classify ...(翻译)
- VMWare 网络连接模式(bridged、NAT、host-only)详解
- IP、TCP、UDP 协议格式,TCP状态机
- 网络防火墙技术
- IIS7 / IIS7.5 URL 重写 HTTP 重定向到 HTTPS
- android 网络编程--socket tcp/ip udp http之间的关系
- [网络流24题] 搭配飞行员
- HTTP 状态码
- tcp/ip协议
- iOS开发工具-网络封包分析工具Charles
- 监控服务器网络是否正常
- Java中通过TCP协议发送和接收数据-Socket编程