UVa 10330 Power Transmission / 最大流
最大流 这题有很多起点和终点 在取2个点(0和n+1) 作为唯一的起点和终点
此外每个点也有容量限制 建图时每条边上的容量为这条边和2个端的容量的最小值 然后EK就行
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int MAX = 110;
int num[MAX];
int a[MAX];
int cap[MAX][MAX];
int flow[MAX][MAX];
int p[MAX];
int n,m,b,d;
int f;
void EK()
{
queue <int> q;
memset(flow,0,sizeof(flow));
f = 0;
while(1)
{
memset(a,0,sizeof(a));
a[0] = 999999999;
q.push(0);
while(!q.empty())
{
int u = q.front();
q.pop();
for(int v = 0; v <= n+1; v++)
{
if(!a[v] && cap[u][v] > flow[u][v])
{
p[v] = u;
q.push(v);
a[v] = min(a[u],cap[u][v] - flow[u][v]);
}
}
}
if(a[n+1] == 0)
break;
for(int u = n+1; u; u = p[u])
{
flow[p[u]][u] += a[n+1];
flow[u][p[u]] -= a[n+1];
}
f += a[n+1];
}
}
int main()
{
int i,x,y,z;
while(scanf("%d",&n)!=EOF)
{
memset(cap,0,sizeof(cap));
for(i = 1;i <= n; i++)
scanf("%d",&num[i]);
scanf("%d",&m);
while(m--)
{
scanf("%d %d %d",&x,&y,&z);
cap[x][y] = z;
cap[x][y] = min(cap[x][y],min(num[x],num[y]));
}
scanf("%d %d",&b,&d);
while(b--)
{
scanf("%d",&x);
cap[0][x] = num[x];
}
while(d--)
{
scanf("%d",&x);
cap[x][n+1] = num[x];
}
EK();
printf("%d\n",f);
}
return 0;
}
UVa 10330 Power Transmission / 最大流的更多相关文章
- UVa 10330 - Power Transmission(最大流--拆点)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- uva 10330 - Power Transmission(网络流)
uva 10330 - Power Transmission 题目大意:最大流问题. 解题思路:増广路算法. #include <stdio.h> #include <string. ...
- UVA 10330 Power Transmission
题意:懒得打了.LUCKY CAT 里有 http://163.32.78.26/homework/q10330.htm 第一个网络流题目.每个节点都有一个容量值.需要拆点.拆成i - > i ...
- light oj 1155 - Power Transmission【拆点网络流】
1155 - Power Transmission PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...
- UVA 11149 - Power of Matrix(矩阵乘法)
UVA 11149 - Power of Matrix 题目链接 题意:给定一个n*n的矩阵A和k,求∑kiAi 思路:利用倍增去搞.∑kiAi=(1+Ak/2)∑k/2iAi,不断二分就可以 代码: ...
- C2. Power Transmission (Hard Edition)(线段相交)
This problem is same as the previous one, but has larger constraints. It was a Sunday morning when t ...
- C2. Power Transmission (Hard Edition) 解析(思維、幾何)
Codeforce 1163 C2. Power Transmission (Hard Edition) 解析(思維.幾何) 今天我們來看看CF1163C2 題目連結 題目 給一堆點,每兩個點會造成一 ...
- uva 10330 最大流
拆点 将节点 i 的容量拆成从 i 到 i+n 的边的容量 套用最大流模板 ac #include <cstdio> #include <cstdlib> #include ...
- UVA 820 --- POJ 1273 最大流
找了好久这两个的区别...UVA820 WA了 好多次.不过以后就做模板了,可以求任意两点之间的最大流. UVA 是无向图,因此可能有重边,POJ 1273是有向图,而且是单源点求最大流,因此改模板的 ...
随机推荐
- rman 使用catalog备份的演示
介绍了如何使用catalog方式做RMAN备份,以及如何取消以catalog方式做备份. 第一步:创建RMAN CATALOG表空间及用户. [oracle@oel-01 ~]$ sqlplus / ...
- Connection for controluser as defined in your configuration failed.
在mysql中使用事件调度器(计划任务), 语句写好了,运行也ok,可是却没有预期的结果.网上总结了非常多计划任务失效的原因.没有一种适合我. 在phpmyadmin中打开事件表,发现以下一串红色的提 ...
- MVC3 验证码
public ActionResult GetValidateCode() { string code = CreateValidateC ...
- Android学习之DragEvent
关于DragEvent Google Android API中是这么说的 Represents an event that is sent out by the system at various t ...
- linux ln 命令(转载)
ln是linux中又一个非常重要命令,它的功能是为某一个文件在另外一个位置建立一个同不的链接,这个命令最常用的参数是-s,具体用法是:ln –s 源文件 目标文件. 当我们需要在不同的目录,用到相同的 ...
- Sublime Text 2使用技巧汇总
一.下载链接: Windows-64bit: http://pan.baidu.com/s/1o6QdKYu 其它版本请移步官网: http://www.sublimetext.com/ 二.破解Li ...
- 深入浅出—JAVA(5)
5.编写程序
- 转: seajs手册与文档之 -- 配置选项
config alias preload debug map base charset timeout noConflict config 可以使用 config 方法来配置seajs. seajs. ...
- Test class should have exactly one public zero-argument constructor
java.lang.Exception: Test class should have exactly one public zero-argument constructor at org.juni ...
- BZOJ 3390: [Usaco2004 Dec]Bad Cowtractors牛的报复
题目 3390: [Usaco2004 Dec]Bad Cowtractors牛的报复 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 53 Solve ...