这题是学着小媛学姐写的..

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include <climits>
using namespace std;
#define N 120 int n, np, nc, m;
int cap[N][N];
int EK(int s, int t)
{
queue<int> q;
int flow[N][N];
int low[N];
int u,v,maxflow=;
int pre[N];
memset(flow,,sizeof(flow));
while()
{
q.push(s);
memset(low,,sizeof(low));
low[s] = INT_MAX;
while(!q.empty())
{
u = q.front();
q.pop();
for(v = ; v <= t; v ++)
{
if(!low[v] && cap[u][v] > flow[u][v])
{
q.push(v);
low[v] = min(low[u], cap[u][v] - flow[u][v]);
pre[v] = u;
}
}
}
if(low[t] == ) break;
for(u = t; u != s; u = pre[u])
{
flow[pre[u]][u] += low[t];
flow[u][pre[u]] -= low[t];
}
maxflow += low[t];
}
return maxflow;
}
int main()
{
char ch;
int from, to, len, ans;
while(~scanf("%d%d%d%d",&n,&np,&nc,&m))
{
memset(cap, , sizeof(cap));
while(m--)
{
scanf(" (%d,%d)%d", &from, &to, &len);
cap[from][to] = len;
}
while(np--)
{
scanf(" (%d)%d",&from, &len);
cap[n+][from] = len;
}
while(nc--)
{
scanf(" (%d)%d",&from, &len);
cap[from][n+] = len;
}
ans = EK(n+, n+);
printf("%d\n",ans);
}
return ;
}

POJ 1459(EK)的更多相关文章

  1. poj 1459 多源多汇点最大流

    Sample Input 2 1 1 2 (0,1)20 (1,0)10 (0)15 (1)20 7 2 3 13 (0,0)1 (0,1)2 (0,2)5 (1,0)1 (1,2)8 (2,3)1 ...

  2. POJ 1459 Power Network / HIT 1228 Power Network / UVAlive 2760 Power Network / ZOJ 1734 Power Network / FZU 1161 (网络流,最大流)

    POJ 1459 Power Network / HIT 1228 Power Network / UVAlive 2760 Power Network / ZOJ 1734 Power Networ ...

  3. Poj(1459),最大流,EK算法

    题目链接:http://poj.org/problem?id=1459 Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Su ...

  4. POJ 1459 网络流 EK算法

    题意: 2 1 1 2 (0,1)20 (1,0)10 (0)15 (1)20 2 1 1 2 表示 共有2个节点,生产能量的点1个,消耗能量的点1个, 传递能量的通道2条:(0,1)20 (1,0) ...

  5. poj 1459 网络流问题`EK

    Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 24930   Accepted: 12986 D ...

  6. 网络流之最大流EK --- poj 1459

    题目链接 本篇博客延续上篇博客(最大流Dinic算法)的内容,此次使用EK算法解决最大流问题. EK算法思想:在图中搜索一条从源点到汇点的扩展路,需要记录这条路径,将这条路径的最大可行流量 liu 增 ...

  7. POJ 1459 Power Network 最大流(Edmonds_Karp算法)

    题目链接: http://poj.org/problem?id=1459 因为发电站有多个,所以需要一个超级源点,消费者有多个,需要一个超级汇点,这样超级源点到发电站的权值就是发电站的容量,也就是题目 ...

  8. POJ 1459:Power Network(最大流)

    http://poj.org/problem?id=1459 题意:有np个发电站,nc个消费者,m条边,边有容量限制,发电站有产能上限,消费者有需求上限问最大流量. 思路:S和发电站相连,边权是产能 ...

  9. poj 1459 Power Network

    题目连接 http://poj.org/problem?id=1459 Power Network Description A power network consists of nodes (pow ...

随机推荐

  1. 用Python编写九九乘法表考虑print自动换行问题

    编写了一个简单的小程序九九乘法表,代码如下: for i in range(1,10): for j in range(1,i+1): print(" %d*%d=%d" % (j ...

  2. set与hash_set

    原文:http://blog.csdn.net/morewindows/article/details/7029587 STL系列之六 set与hash_set set和hash_set是STL中比较 ...

  3. 慎用preg_replace危险的/e修饰符(一句话后门常用)

    要确保 replacement 构成一个合法的 PHP 代码字符串,否则 PHP 会在报告在包含 preg_replace() 的行中出现语法解析错误     preg_replace函数原型: mi ...

  4. How to Install and Configure Nginx from Source on centos--转

    1.CentOS - Installing Nginx from source http://articles.slicehost.com/2009/2/2/centos-installing-ngi ...

  5. c#读写ini配置文件示例

    虽然c#里都是添加app.config 并且访问也很方便 ,有时候还是不习惯用他.那么我们来做个仿C++下的那种ini配置文件读写吧     其他人写的都是调用非托管kernel32.dll.我也用过 ...

  6. C语言中和指针相关的四道题目

    例子1. void fun (int *x , int *y) { printf("%d, %d", *x, *y) ; *x = 3; *y = 4;} main(){ int ...

  7. find the nth digit

    Problem Description 假设:S1 = 1S2 = 12S3 = 123S4 = 1234.........S9 = 123456789S10 = 1234567891S11 = 12 ...

  8. 测试你是否和LTC水平一样高

    Problem Description 大家提到LTC都佩服的不行,不过,如果竞赛只有这一个题目,我敢保证你和他绝对在一个水平线上!你的任务是:计算方程x^2+y^2+z^2= num的一个正整数解. ...

  9. How to make remote key fob for 2002 BMW 3 series

    Here share with you on how to make remote key fob for 2002 BMW 3 series: Method 1: 1. Working within ...

  10. iOS - UI - UISegmentedControl

    1.UISegmentedControl NSArray * array = @[@"red",@"green",@"yellow",@&q ...