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)的 ...
随机推荐
- LA-3135 - Argus(优先队列)
3135 - Argus A data stream is a real-time, continuous, ordered sequence of items. Some examples incl ...
- Surround the Trees(凸包求周长)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- JS获取中文拼音首字母,并通过拼音首字母高速查找页面内的中文内容
实现效果: 图一: 图二: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGVzdGNzX2Ru/font/5a6L5L2T/fontsize/400/f ...
- Yii Framework2.0开发教程(2)使用表单Form
第一步.接着教程(1).我们在controllers/ZhyoulunController.php中加入两处, 1) use app\models\EntryForm; 和 2) public fun ...
- 异常关闭MyEclipse 8.6后,不能重启
删掉这两个文件.
- iOS UIWebView 之 UIProgressView
之前做等待跳转都是用UIActivityIndicatorView ,后来做webView 加载页面的时候,发现了一个特别好用又超级炫酷的加载提示NJKWebViewProgress,作者巧妙的通过计 ...
- c++设置输出精度
float类型的精度6-7位,double类型的变量15-16位,但是float占四个字节,double占八个字节, 但能用float类型不要用double因为double占的字节数多,而且运算速度要 ...
- 笔记之Cyclone IV 第一卷第一章FPGA 器件系列概述
因为本人用的黑金四代开发板,中央芯片采用ALTERA的cycloneIV E,所以就此器件阅读altera官网资料,并做相应的笔记,以便于以后查阅 Cyclone IV 器件系列具有以下特性:■ 低成 ...
- C#实现时间戳转化
/// <summary> /// 时间戳转为C#格式时间 /// </summary> /// <param name=”timeStamp”></para ...
- zabbix 添加主机成功失败判断
zabbix 成功添加后: $VAR1 = bless( { 'version' => 0, 'content' => { 'jsonrpc' => '2.0', 'id' => ...