求从电站->调度站->消费者的最大流,给出一些边上的容量。和电站和消费者能够输入和输出的最大量。

加入一个超级源点和汇点,建边跑模板就能够了。

两个模板逗能够。

#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#define inf 0x3f3f3f3f
#define eps 1e-6
#define ll __int64
const int maxn=110;
using namespace std; int n,m,np,nc,s,t;
int level[maxn],c[maxn][maxn]; bool makelevel()
{
memset(level,0,sizeof level);
level[s]=1;
int q[maxn];
int fro=0,iq=0;
q[iq++]=s;
int i,v;
while(fro!=iq)
{
v=q[fro++];
for(i=1;i<=n+2;i++)//注意点的编号
{
if(!level[i]&&c[v][i])
{
level[i]=level[v]+1;
q[iq++]=i;
}
}
}
if(!level[t]) return 0;
return 1;
} int dfs(int now,int maxf)
{
if(now==t) return maxf;
int ret=0;
for(int i=1;maxf&&i<=n+2;i++)//注意点的编号
{
if(c[now][i]&&level[now]+1==level[i])
{
int tmp=dfs(i,min(maxf,c[now][i]));
c[now][i]-=tmp;
c[i][now]+=tmp;
ret+=tmp;
maxf-=tmp;
}
}
return ret;
} int dinic()
{
int ans=0;
while(makelevel()) ans+=dfs(s,inf);
return ans;
} /*
int c[maxn][maxn],p[maxn]; bool bfs()
{
queue<int> q;
bool vis[maxn];
memset(vis,0,sizeof vis);
memset(p,-1,sizeof p);
q.push(s);
vis[s]=1;
while(!q.empty())
{
int e=q.front();
if(e==t) return 1;
q.pop();
for(int i=1;i<=n+2;i++)//注意点的范围
{
if(c[e][i]&&!vis[i])
{
vis[i]=1;
p[i]=e;
q.push(i);
}
}
}
return 0;
} int ek()
{
int u,ans=0,mn;
while(bfs())
{
mn=inf;
u=t;
while(p[u]!=-1)
{
mn=min(mn,c[p[u]][u]);
u=p[u];
}
ans+=mn;
u=t;
while(p[u]!=-1)
{
c[p[u]][u]-=mn;
c[u][p[u]]+=mn;
u=p[u];
}
}
return ans;
}*/ int main()
{
int i,a,b,cc;
while(~scanf("%d%d%d%d",&n,&np,&nc,&m))
{
s=n+1,t=n+2;
memset(c,0,sizeof c);
for(i=0;i<m;i++)
{
while(getchar()!='(');
scanf("%d,%d)%d",&a,&b,&cc);
c[a+1][b+1]=cc;
}
for(i=0;i<np;i++)
{
while(getchar()!='(');
scanf("%d)%d",&a,&b);
c[s][a+1]=b;
}
for(i=0;i<nc;i++)
{
while(getchar()!='(');
scanf("%d)%d",&a,&b);
c[a+1][t]=b;
}
printf("%d\n",dinic());
}
return 0;
}

poj1459 Power Network --- 最大流 EK/dinic的更多相关文章

  1. POJ1459 Power Network —— 最大流

    题目链接:https://vjudge.net/problem/POJ-1459 Power Network Time Limit: 2000MS   Memory Limit: 32768K Tot ...

  2. poj1087 A Plug for UNIX & poj1459 Power Network (最大流)

    读题比做题难系列…… poj1087 输入n,代表插座个数,接下来分别输入n个插座,字母表示.把插座看做最大流源点,连接到一个点做最大源点,流量为1. 输入m,代表电器个数,接下来分别输入m个电器,字 ...

  3. POJ1459 Power Network(网络最大流)

                                         Power Network Time Limit: 2000MS   Memory Limit: 32768K Total S ...

  4. poj1459 Power Network (多源多汇最大流)

    Description A power network consists of nodes (power stations, consumers and dispatchers) connected ...

  5. poj 1459 Power Network : 最大网络流 dinic算法实现

    点击打开链接 Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 20903   Accepted:  ...

  6. POJ1459 - Power Network

    原题链接 题意简述 原题看了好几遍才看懂- 给出一个个点,条边的有向图.个点中有个源点,个汇点,每个源点和汇点都有流出上限和流入上限.求最大流. 题解 建一个真 · 源点和一个真 · 汇点.真 · 源 ...

  7. POJ1459 Power Network 网络流 最大流

    原文链接http://www.cnblogs.com/zhouzhendong/p/8326021.html 题目传送门 - POJ1459 题意概括 多组数据. 对于每一组数据,首先一个数n,表示有 ...

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

    https://vjudge.net/problem/POJ-1459 题解转载自:優YoU http://user.qzone.qq.com/289065406/blog/1299339754 解题 ...

  9. POJ1459:Power Network(dinic)

    题目链接:http://poj.org/problem?id=1459 题意:有n个结点,np个发电站,nc个消费者,m个电力运输线.接下去是m条边的信息(u,v)cost,cost表示边(u,v)的 ...

随机推荐

  1. poj3308Paratroopers(最小割)

    题目请戳这里 题目大意:给一个n*m的矩阵,给一些点(ri,ci)表示该点在第ri行第ci列.现在要覆盖所有的点,已知覆盖第i行代价为Ri,覆盖第j列代价为Cj.总代价是累乘的,求最小总代价能覆盖所有 ...

  2. 链接分析算法之:HillTop算法

      链接分析算法之:HillTop算法     Hilltop算法是由Krishna Baharat 在2000年左右研究的,于2001年申请专利,但是有很多人以为Hilltop算法是由谷歌研究的.只 ...

  3. 使用Git上传代码到GitHub详细的不能再详细教程

    据说不会用GitHub的程序员连菜鸟都不算,确实,GitHub上有大量优秀的代码,我们也可以将自己的代码分享上去. 首先,你要有一个GitHub的账号,https://github.com/在官网注册 ...

  4. BZOJ 2060: [Usaco2010 Nov]Visiting Cows 拜访奶牛( dp )

    树形dp..水 ------------------------------------------------------------------------ #include<cstdio& ...

  5. fastxml Jackson JsonNode (ObjectNode) 转 List

    做环聊开发, Java 后台示例 用的 fastxml Jackson 解析json(擦, 狗屎, 不能支持下国产吗?) 有的json字段是数组, 发现不会解析了, 谷歌了下, 用以下方法可行,(不知 ...

  6. DE1-SOC连接设定

    将电源供应器插上电源接口. 使用白色的USB Type B线材将计算机与DE1-SoC上的USB-Blaster II接口连接.此接口主要负责FPGA配置以及HPS Debug使用. 使用Mini-U ...

  7. int_float_double数据类型的存储格式。

    一段用来检测编辑器存储方式的程序 //date : 2013/8/16 //designer :pengxiaoen //function check the C programmable langu ...

  8. 将 jsp 页面的值 传到struts2 action中(不是表单中的值)

    JSP: 页面: <%@ page language="java"  pageEncoding="GBK"%> <%@taglib prefi ...

  9. centos php扩展开发流程

    原文:centos php扩展开发流程 一.安装php centos 默认 yum 安装 php 版本为 5.3, 很多php框架基本上要求5.4以上版本,这时候不能直接 用 yum install ...

  10. 解决TCP网络传输“粘包”问题

    当前在网络传输应用中,广泛采用的是TCP/IP通信协议及其标准的socket应用开发编程接口(API).TCP/IP传输层有两个并列的协议:TCP和UDP.其中TCP(transport contro ...