HDU 3549【网络流入门--然而我还是XXX】
2015-09-08 20:31
716 查看
0 0.。。。。我记得上个学期说要入门网络流。。。0 0.。。。。。。对不起后来为什么我都忘了这茬。。。然而现在已经没什么卵用了。。。
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/bye.gif)
其实这代码还是挺形象的。。。。就像水在咕咕地流过去。。。第一篇网络流。。。
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/bye.gif)
其实这代码还是挺形象的。。。。就像水在咕咕地流过去。。。第一篇网络流。。。
#include <cstdio> #include <iostream> #include <cstring> #include <queue> using namespace std; #define maxn 16 #define inf 1100 int cap[maxn][maxn],c[maxn],flow[maxn][maxn],p[maxn]; queue<int>que; int n,ans; void solve() { int flag=1; memset(flow,0,sizeof(flow)); while(flag) { memset(c,0,sizeof(c)); que.push(1); c[1]=inf;p[1]=-1; while(!que.empty()) { int pos=que.front(); que.pop(); for(int i=1;i<=n;i++) { if(!c[i]&&flow[pos][i]<cap[pos][i]) { c[i]=min(cap[pos][i]-flow[pos][i],c[pos]); //c表示当前节点在这次的循环中流过了多少水,如果是0的话就表示没有水流过,可以流,但是流过的水应该是从父节点流来的水和现实中能流过的水的最小值,这样才保证合法。c[1]为inf,表示这里可以有无穷多的水流流过。戳萌点了。。 que.push(i); p[i]=pos; } } } if(c ==0) { flag=0; } ans+=c ; int tmp=n; while(tmp!=-1) { flow[p[tmp]][tmp]+=c ; //如果这次成立,就更新每个管道流过的水流 flow[tmp][p[tmp]]-=c ; //回流?这里不是很懂 tmp=p[tmp]; } } } int main() { int T,cas=0; cin>>T; while(T--) { memset(cap,0,sizeof(cap)); ans=0; int m; int x,y,z; cin>>n>>m; while(m--) { cin>>x>>y>>z; cap[x][y]+=z; //注意这里,因为可能有多个通道,但是达到的效果是叠加的 } solve(); printf("Case %d: ",++cas); cout<<ans<<endl; } return 0; }
相关文章推荐
- HDU 3572Task Schedule(网络流)
- POJ 1459:Power Network 能源网络
- POJ 1459:Power Network 能源网络
- 网络请求时WiFi边上的菊花
- POJ 1273:Drainage Ditches 网络流模板题
- POJ 1273:Drainage Ditches 网络流模板题
- POJ 1149:PIGS 网络流经典题
- POJ 1149:PIGS 网络流经典题
- HTTP - 条件请求
- iOS 异步请求网络数据,传值问题
- 传输层(2)-TCP连接的建立和终止、TIME_WAIT状态
- 27-监管网络状态信息netstat
- 网络通信之网页源码查看 并显示屏幕上
- HTTP Status 404 - There is no Action mapped for namespace [/] and action name [login!welcome] associ
- Android第六讲——数据存储(五种)SharedPreferences、内部存储(缓存cache)、外部存储(Sdcrad)、SQLite数据库、网络存储
- HTTP学习
- 使用IOCP需要注意的一些问题~~(不断补充)
- iOS基础知识:Objective-C 之 网络请求
- TCP是如何保证包的顺序传输?
- nginx_tcp模块集成到openresty