F - 传输数据

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
Submit Status

机房里面有m台电脑,n台网线,每条网线都每秒中最多传送的数据量,现在需要你计算从标号为1的电脑传送数据到编号为m的电脑,问一秒内最多传送多少数据?

Input

第1行: 两个用空格分开的整数N(0≤N≤200)和 M(2≤M≤200)。N网线的数量,M是电脑的数量。

第二行到第N+1行: 每行有三个整数,Si,Ei 和 Ci。Si 和 Ei (1≤Si,Ei≤M) 指明电脑编号,数据从 Si 流向 Ei。Ci(0≤Ci≤10,000,000)是这条网线的最大容量。

Output

输出一个整数,即排水的最大流量。

Sample input and output

Sample Input Sample Output
5 4
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10
50

解题报告:

解题报告:

这是一道赤裸裸的最大流题目,我使用了ek算法,虽然效率不高,但是本题数据规模不大,所以直接用ek算法解决.

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;
const int maxn = + ;
int c[maxn][maxn]; //流量限制
int f[maxn][maxn]; //目前流量
int p[maxn]; //残余流量
int pre[maxn]; //路径记录
const int inf = 0x5fffffff;
int n,m;
queue<int>q; int ek(int st,int ed)
{
int flow = ;
while()
{
memset(p,,sizeof(p));
p[st] = inf,pre[st] = ;
q.push(st);
while(!q.empty())
{
int x = q.front();q.pop();
for(int i = ; i <= m ; ++ i)
if (!p[i] && f[x][i] < c[x][i]) //允许增广
{
q.push(i);
pre[i] = x; //路径记录
p[i] = min(c[x][i] - f[x][i] , p[x]);
}
}
if (!p[ed]) // 增广路搜寻完毕,无可增加的流量
break;
int cur = ed;
while(cur)
{
f[pre[cur]][cur] += p[ed];
f[cur][pre[cur]] -= p[ed];
cur = pre[cur];
}
flow += p[ed];
}
return flow;
} int main(int argc,char *argv[])
{
memset(c,,sizeof(c));
memset(f,,sizeof(f));
scanf("%d%d",&n,&m);
while(n--)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
c[u][v] += w;
}
printf("%d\n",ek(,m));
return ;
}

最新文章

  1. python 二分法查找实例(递归、循环)
  2. Hibernate.initialize(Obj)用法
  3. EntityFramework 6.0&lt; Code First &gt; 连接 Mysql数据库
  4. Maven构建项目速度慢问题解决
  5. J2EE分布式事务中的提交、回滚方法调用异常。
  6. AngularJS中文介绍
  7. EasyUI DataGrid编辑单元格时使用combogrid
  8. hdu 4198 Quick out of the Harbour(BFS+优先队列)
  9. 【python】lambda创建匿名函数
  10. 关于a标签的用法总结
  11. mysql 如何查看sql语句执行时间和效率
  12. iframe伪造ajax
  13. 非阻塞 sleep
  14. c++运算符重载---20
  15. python unittest单元测试框架-1
  16. 【JUC源码解析】DelayQueue
  17. 数据源与JNDI资源实现JSP数据库连接池实例
  18. python3爬虫.4.下载煎蛋网妹子图
  19. Lintcode---二叉树的最大节点
  20. 一次Mysql连接池卡死导致服务无响应问题分析(.Net Mysql.Data 6.9.9)

热门文章

  1. 10招搞定web设计风格指南
  2. 01_docker学习总结
  3. JavaScript面向对象之类的继承
  4. 【转】Android NDK开发入门实例
  5. Animation Override Controller动画重载器
  6. 华为測试 字符串运用-password截取
  7. 飘逸的python - 解决一个有限制的组合需求
  8. 使用Xshell连接Ubuntu
  9. python-生成随机字符
  10. .NET批量大数据插入性能分析及比较