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

 #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. 自增锁ID复用问题

    mysql> select * from pp; +----+------+ | id | name | +----+------+ | xx | | xx | | xx | | xx | | ...

  2. 在应用程序中实现对NandFlash的操作

    以TC58NVG2S3ETA00 为例: 下面是它的一些物理参数: 图一 图二 图三 图四 图五 图6-0 图6-1 说明一下,在图6-1中中间的那个布局表可以看做是实际的NandFlash一页数据的 ...

  3. Collections.sort(List<T> Comparator) 自定义排序

    Collections.sort(basicinfoList, new Comparator<MlisBasicinfo>() { @Override public int compare ...

  4. 第一个c++程序 helloworld

    // helloworld.cpp : 定义控制台应用程序的入口点.// #include "stdafx.h"#include "iostream" int ...

  5. UIView的生命周期总结

    序言: loadView.viewDidLoad.viewDidAppear.initWithNibName.awakeFromNib等经常出现在UIViewController中的方法介绍. 这些方 ...

  6. WPF 之 style文件的引用

    总结一下WPF中Style样式的引用方法. 一.内联样式: 直接设置控件的Height.Width.Foreground.HorizontalAlignment.VerticalAlignment等属 ...

  7. EF——使用Data Annotations和Fluent API配置数据库的映射配置 02.01(转)

    要更改EF中的默认配置有两个方法,一个是用Data Annotations(在命名空间System.ComponentModel.DataAnnotations;),直接作用于类的属性上面;还有一个就 ...

  8. C语言第六节基本运算符

    算术运算 C语言一共有34种运算符,包括了常见的加减乘除运算 加法运算+ 除开能做加法运算,还能表示正号:+5.+90 减法运算- 除开能做减法运算,还能表示符号:-10.-29 乘法运算* 注意符号 ...

  9. A - 敌兵布阵

    Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些 ...

  10. mysql前n条查询

    可以利用——LIMIT——来完成这项功能. LIMIT可以实现top N查询,也可以实现M至N(某一段)的记录查询,具体语法如下: SELECT * FROM MYTABLE ORDER BY AFI ...