poj1459 Power Network --- 最大流 EK/dinic
求从电站->调度站->消费者的最大流,给出一些边上的容量。和电站和消费者能够输入和输出的最大量。
加入一个超级源点和汇点,建边跑模板就能够了。
两个模板逗能够。
#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的更多相关文章
- POJ1459 Power Network —— 最大流
题目链接:https://vjudge.net/problem/POJ-1459 Power Network Time Limit: 2000MS Memory Limit: 32768K Tot ...
- poj1087 A Plug for UNIX & poj1459 Power Network (最大流)
读题比做题难系列…… poj1087 输入n,代表插座个数,接下来分别输入n个插座,字母表示.把插座看做最大流源点,连接到一个点做最大源点,流量为1. 输入m,代表电器个数,接下来分别输入m个电器,字 ...
- POJ1459 Power Network(网络最大流)
Power Network Time Limit: 2000MS Memory Limit: 32768K Total S ...
- poj1459 Power Network (多源多汇最大流)
Description A power network consists of nodes (power stations, consumers and dispatchers) connected ...
- poj 1459 Power Network : 最大网络流 dinic算法实现
点击打开链接 Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 20903 Accepted: ...
- POJ1459 - Power Network
原题链接 题意简述 原题看了好几遍才看懂- 给出一个个点,条边的有向图.个点中有个源点,个汇点,每个源点和汇点都有流出上限和流入上限.求最大流. 题解 建一个真 · 源点和一个真 · 汇点.真 · 源 ...
- POJ1459 Power Network 网络流 最大流
原文链接http://www.cnblogs.com/zhouzhendong/p/8326021.html 题目传送门 - POJ1459 题意概括 多组数据. 对于每一组数据,首先一个数n,表示有 ...
- POJ-1459 Power Network(最大流)
https://vjudge.net/problem/POJ-1459 题解转载自:優YoU http://user.qzone.qq.com/289065406/blog/1299339754 解题 ...
- POJ1459:Power Network(dinic)
题目链接:http://poj.org/problem?id=1459 题意:有n个结点,np个发电站,nc个消费者,m个电力运输线.接下去是m条边的信息(u,v)cost,cost表示边(u,v)的 ...
随机推荐
- Tomcat7 + JRebel6.3.0 + IntelliJ idea 热部署配置过程+错误分析
以前使用Tomcat的时候直接就可以热部署,现在换了一个使用Spring框架的项目突然就不能热部署了. 网上说在tomcat里conf/context.xml中加入 <Context antiJ ...
- poj 1664 put apples(dfs)
题目链接:http://poj.org/problem?id=1664 思路分析:数据较小,考虑深度优先搜索搜索解空间. 代码如下: #include <iostream> using n ...
- Flow Problem(最大流)
Flow Problem Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Tot ...
- NAT简单介绍
NAT本质就是让一群机器公用同一个IP.还有一个重要的用途是保护NAT内的主机不受外界攻击 NAT类型: 1.Full Cone:IPport不受限 Full Cone仅仅做单纯的地址转换,不正确进出 ...
- [置顶] C++ Pirate: Lambda vs Bind
Lambda 与 Bind的性能比较 转载请说明出处:http://blog.csdn.net/cywosp/article/details/9379403 先让我们看看下面函数: template ...
- C#_会员管理系统:开发四(日志查看)
新建一个日志查看窗体: 日志需要的登录时间和登录状态信息由用户刚登录程序时就提供,所以在登录窗体(VIPLogin.cs)中添加代码: //定义一个全局变量 Uid; //用于获取登录成功后的用户名 ...
- iframe框架子页面与父页面间的通信
需要注意的问题:页面最好放在服务器上测试避免跨域问题. 具体参考:http://www.cnblogs.com/ljhero/archive/2011/07/09/2101540.html
- JSONToObejct 问题 part 1
直接截图,就明白了 前端的处理 这里用到 JSON2.stringify() 这个方法是将对象(object) 转换成 [{},{},+...+,{}] 这种键值对形式的数据,不然rows只是一个选 ...
- Java--再次理解多态
Java中多态性(polymorphism)的实现 什么是多态 1. 面向对象的三大特性:封装.继承.多态.从一定角度来看,封装和继承几乎都是为多态而准备的.这是我们最后一个概念,也是最重要的知识点. ...
- 设置QPushButton的平面与突出(遍历控件)
#include "ui_maindialog.h" #include "maindialog.h" #include <QState> #incl ...