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