POJ 1459(EK)
这题是学着小媛学姐写的..
#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)的更多相关文章
- 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 ...
- 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 ...
- Poj(1459),最大流,EK算法
题目链接:http://poj.org/problem?id=1459 Power Network Time Limit: 2000MS Memory Limit: 32768K Total Su ...
- 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) ...
- poj 1459 网络流问题`EK
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 24930 Accepted: 12986 D ...
- 网络流之最大流EK --- poj 1459
题目链接 本篇博客延续上篇博客(最大流Dinic算法)的内容,此次使用EK算法解决最大流问题. EK算法思想:在图中搜索一条从源点到汇点的扩展路,需要记录这条路径,将这条路径的最大可行流量 liu 增 ...
- POJ 1459 Power Network 最大流(Edmonds_Karp算法)
题目链接: http://poj.org/problem?id=1459 因为发电站有多个,所以需要一个超级源点,消费者有多个,需要一个超级汇点,这样超级源点到发电站的权值就是发电站的容量,也就是题目 ...
- POJ 1459:Power Network(最大流)
http://poj.org/problem?id=1459 题意:有np个发电站,nc个消费者,m条边,边有容量限制,发电站有产能上限,消费者有需求上限问最大流量. 思路:S和发电站相连,边权是产能 ...
- poj 1459 Power Network
题目连接 http://poj.org/problem?id=1459 Power Network Description A power network consists of nodes (pow ...
随机推荐
- 大型JavaScript应用程序架构模式
11月中旬在伦敦举行的jQuery Summit顶级大会上有个session讲的是大型JavaScript应用程序架构,看完PPT以后觉得甚是不错,于是整理一下发给大家共勉. PDF版的PPT下载地址 ...
- java 哈夫曼编码
//哈夫曼树类 public class HaffmanTree { //最大权值 ; int nodeNum ; //叶子结点个数 public HaffmanTree(int n) { this. ...
- Adding DTrace Probes to PHP Extensions
By cj on Dec 06, 2012 The powerful DTrace tracing facility has some PHP-specific probes that can b ...
- Spring Mvc返回html页面404错误解决记录--转载
原文地址:http://53873039oycg.iteye.com/blog/2061992 以前使用Spring Mvc时候都是返回jsp页面或者ftl页面,昨天想返回html页面,spring- ...
- LeetCode48 Rotate Image
题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...
- c++ 设计模式1
从面向对象谈起 1) 底层思维:向下,如何把握及其底层,从微观理解对象构造 (语言构造.编译转换.内存模型.运行时机制) 抽象思维: 向上,如何将我们的周围世界抽象为程序代码 (面向对象.组件封装 ...
- 如何利用OCS存取PHP session全局变量
如何利用OCS存取PHP session全局变量 阿里云技术团队:余汶龙 一.场景介绍 用户在利用PHP搭建网站时,会把一些信息存放在$_SESSION全局变量里,可以很方便的存取.在PHP的in ...
- 从敏捷开发到小团队SVN
一.敏捷之惑 敏捷开发,有一个很好的实践,“每天都可以产生一个可用于发布的版本”. 以前对这句话感到非常的困惑,因为我们手中的项目是残缺的,基本只是程序的一个功能片段,在未集成之前如何发布得了?当然这 ...
- JavaScript 编写线程代码引用Concurrent.Thread.js
马上来下载和使用源码吧!假定你已经将下载的源码保存到一个名为Concurrent.Thread.js的文件夹里,在进行任何操作之前,先运行如下程序,这是一个很简单的功能实现: <script t ...
- 借助linq2db使用Linq访问MySQL
linq2db (@github)支持Linq访问多种数据库.使用它操作MySQL非常简单,但使用方式上有一些“新奇”,特记录一下. 下载安装(@NuGet)以及使用教程(@For MySQL). 使 ...