UESTC_传输数据 2015 UESTC Training for Graph Theory<Problem F>
F - 传输数据
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
机房里面有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 ;
}
UESTC_传输数据 2015 UESTC Training for Graph Theory<Problem F>的更多相关文章
- UESTC_排名表 2015 UESTC Training for Graph Theory<Problem I>
I - 排名表 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit S ...
- UESTC_方老师和农场 2015 UESTC Training for Graph Theory<Problem L>
L - 方老师和农场 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
- UESTC_王之盛宴 2015 UESTC Training for Graph Theory<Problem K>
K - 王之盛宴 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit ...
- UESTC_小panpan学图论 2015 UESTC Training for Graph Theory<Problem J>
J - 小panpan学图论 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) S ...
- UESTC_韩爷的情书 2015 UESTC Training for Graph Theory<Problem H>
H - 韩爷的情书 Time Limit: 6000/2000MS (Java/Others) Memory Limit: 262144/262144KB (Java/Others) Subm ...
- UESTC_树上的距离 2015 UESTC Training for Graph Theory<Problem E>
E - 树上的距离 Time Limit: 2000/1000MS (Java/Others) Memory Limit: 262143/262143KB (Java/Others) Subm ...
- UESTC_邱老师的脑残粉 2015 UESTC Training for Graph Theory<Problem D>
D - 邱老师的脑残粉 Time Limit: 12000/4000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Sub ...
- UESTC_秋实大哥与时空漫游 2015 UESTC Training for Graph Theory<Problem C>
C - 秋实大哥与时空漫游 Time Limit: 4500/1500MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Su ...
- UESTC_秋实大哥带我飞 2015 UESTC Training for Graph Theory<Problem B>
B - 秋实大哥带我飞 Time Limit: 300/100MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit ...
随机推荐
- 给Select赋值 innerHTML 不兼容IE6\IE7\IE8\IE9
<select class="b-select" id="location-province" name="Province" def ...
- 插入排序(Insertion Sort)
这是排序算法中最常见的排序方法,也是初学者使用最多的.有时候我们在生活中也会不自觉地用到插入排序,例如: 给手里的牌排序 这是最常见的例子之一,我们通常从纸牌的一边开始看,找到一张位置不正确的,把它拿 ...
- 可持久化Trie树
代码 ; struct PerTrie { ][ChSize]; ]; void init() { memset(next[],,])); inf[]=; id=; } int GetId(char ...
- vim 的配色方案
浅色: http://www.vimninjas.com/2012/09/14/10-light-colors/ 深色: http://www.vimninjas.com/2012/08/26/10- ...
- 【多线程】--生产者消费者模式--synchronized版本
在实现生产者消费者模式之前,我们先了解一下线程的5种状态:被创建.运行.冻结.消亡.阻塞,如下图: 在Jdk1.5发布之前,我们实现生产者消费者模式一般使用synchronized + while循环 ...
- Good Teacher(模拟)
Good Teacher Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Statu ...
- MapReduce源代码浅析
Thanks @读程序的手艺人 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaHVvemhhbmZlbmc=/font/5a6L5L2T/fontsize ...
- jquery使用load开展局部刷新没有效果
jquery使用load开展局部刷新没有效果 jquery使用load进行局部刷新没有效果我的代码 <html><head><meta charset="u ...
- Hacker(九)----黑客攻防前准备1
黑客在入侵Internet中其他电脑之前,需要做一系列准备工作,包括在电脑中安装虚拟机.准备常用的工具软件及掌握常用的攻击方法. 一.在计算机中搭建虚拟环境 无论时攻击还是训练,黑客都不会拿实体计算机 ...
- [跟我学spring][Bean的作用域]
Bean的作用域 什么是作用域呢?即“scope”,在面向对象程序设计中一般指对象或变量之间的可见范围.而在Spring容器中是指其创建的Bean对象相对于其他Bean对象的请求可见范围. Sprin ...