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 ...
随机推荐
- JSTL解析——007——fmt标签库02
各位亲们,近期事情比较多,没更新,come on! 1.<fmt:bundle>/<fmt:message>/<fmt:param>资源国际化标签 java中使用R ...
- 对每个用户说hello
#!/bin/bash #对每个用户说hello #用户数 Lines=`wc -l /etc/passwd | cut -d' ' -f1` $Lines`; do echo "Hello ...
- mycat实例(2)
全局序列号 数据切分后,原有的关系数据库中的主键约束在分布式条件下将无法使用,因此需要引入外部机制保证数据唯一性标识,这种保证全局性的数据唯一标识的机制就是全局序列号(sequence). 1. 本地 ...
- cocos2d-x 3.0rc开发指南:Windows下Android环境搭建
安装工具 1. 配置JDK JDK下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html 本人的系统是Win7 ...
- Hacker(十)----常用入侵工具
黑客若想攻击目标计算机,仅靠DOS命令是无法完成的,还需要一些功能强大的入侵工具,如端口扫描工具.网络嗅探工具.木马制作工具及远程控制工具等. 一.端口扫描工具 端口扫描工具有扫描端口的功能,所谓端口 ...
- Cisco cmd 命令
1.enable 开启全局配置模式:disable 禁用配置模式 2.config进入配置模式 3.line 设置进入用户模式密码:分为 line aux 0;line console 0;line ...
- iOS 发布证书错误 Your build settings specify a provisioning profile with the UUID, no provisioning profile was found
解决办法 1.找到项目中的**.xcodeproj文件,点击右键,show package contents(打开包内容). 2.打开后找到project.pbxproj文件,用文本编辑器打开.其实就 ...
- iOS-OC-基础-NSString常用方法
NSString常用方法和属性 //compare 比较字符串升序.相同还是降序,比较原理:首先比较第一个字符(ASCII码比较),如果是升序就为升序,如果相同比较下一个字符... NSString ...
- struts2 注解方式
struts2扫描方法: 扫描其位于包的命名注解的类 “struts, struts2, action 或 actions“. 接着,扫描相匹配下列任一条件的文件: 实例了 com.opensymph ...
- 使用Promise规定来处理ajax请求的结果
ajax()返回结果是成功的,调用done()中的回调函数: 失败则调用fail()中的回调函数; always()的回调函数不管成功是否都会调用: 可以是使用then()函数代替done()和fai ...