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 ...
随机推荐
- 【转】win32,win64编程永恒;语言编程需要注意的64位和32机器的区别
原文网址:http://www.cnblogs.com/kex1n/archive/2010/10/06/1844737.html 一.数据类型特别是int相关的类型在不同位数机器的平台下长度不同.C ...
- WEB打印插件jatoolsPrinter
为什么选择 jatoolsPrinter 免费版? 支持无预览直接打印 真正免费,不加水印,没有ip或域名限制,不限时间,兼容ie6+ 无须注册,下载即用 提供经过微软数字签名的cab自动安装包,安装 ...
- Hdu4742-Pinball Game 3D(cdq分治+树状数组)
Problem Description RD is a smart boy and excel in pinball game. However, playing common 2D pinball ...
- python 弄github代码库列表
1.底 项目要求,征求github的repo的api,为了能够提取repo对数据进行分析. 研究一天.最终克服该问题,較低下. 由于github的那个显示repo的api,列出了 ...
- StaggeredGridView+universal-image-loader载入网路图片实现瀑布流
StaggeredGridView 开源lib https://github.com/maurycyw/StaggeredGridView 文章demo下载地址 http://download.c ...
- ARM9嵌入式学习笔记(1)-Linux命令
ARM9嵌入式学习笔记(1)-Linux命令 实验1-1-2 Linux常见命令使用 添加用户useradd smb; 设置账户密码passwd smb; 切换用户su - root 关机命令shut ...
- Repeater里面加上if判断
//创建时绑定 protected void ItemCreated(object sender, RepeaterItemEventArgs e) { if (e.Item.DataItem != ...
- Know Thy Complexities!
http://bigocheatsheet.com/ Hi there! This webpage covers the space and time Big-O complexities of c ...
- C# socket网络编程 基于TCP协议
socket 服务器端: 1.创建socket Socket tcpClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ...
- String.format Tutorial
String format(String format, Object... args) The format specifiers for general, character, and numer ...