uva 10330 最大流
拆点 将节点 i 的容量拆成从 i 到 i+n 的边的容量 套用最大流模板 ac
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iostream>
#define maxn 210
#define INF 0x7fffffff
#define inf 10000000
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
using namespace std; int n, cap[maxn][maxn], a[maxn], m, flow[maxn][maxn], p[maxn]; int maxflow()
{
queue<int> q;
int f = 0;
memset(flow, 0, sizeof(flow));
while(true)
{
memset(a, 0, sizeof(a));
a[0] = inf;
q.push(0);
while(!q.empty())
{
int u = q.front();
q.pop();
for(int i = 1; i <= n; ++ i)
{
if(!a[i] && cap[u][i] > flow[u][i])
{
p[i] = u;
q.push(i);
a[i] = min(a[u], cap[u][i]-flow[u][i]);
}
}
}
if(!a[n]) break;
for(int i = n; i != 0; i = p[i])
{
flow[p[i]][i] += a[n];
flow[i][p[i]] -= a[n];
}
f += a[n];
}
return f;
} int main()
{
while(scanf("%d", &n) == 1)
{
memset(cap, 0, sizeof(cap));
for(int i = 1; i <= n; ++ i)
{
int temp;
scanf("%d", &temp);
cap[i][i+n] = temp;
}
scanf("%d", &m);
for(int i = 0; i < m; ++ i)
{
int x, y, c;
scanf("%d%d%d", &x, &y, &c);
cap[x+n][y] = c;
}
int a, b;
scanf("%d%d", &a, &b);
for(int i = 0; i < a; ++ i)
{
int x;
scanf("%d", &x);
cap[0][x] = inf;
}
for(int i = 0; i < b; ++ i)
{
int x;
scanf("%d", &x);
cap[x+n][2*n+1] = inf;
}
n = n*2+1;
printf("%d\n", maxflow());
}
return 0;
}
uva 10330 最大流的更多相关文章
- uva 10330 - Power Transmission(网络流)
uva 10330 - Power Transmission 题目大意:最大流问题. 解题思路:増广路算法. #include <stdio.h> #include <string. ...
- UVa 10330 - Power Transmission(最大流--拆点)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVa 10330 Power Transmission / 最大流
最大流 这题有很多起点和终点 在取2个点(0和n+1) 作为唯一的起点和终点 此外每个点也有容量限制 建图时每条边上的容量为这条边和2个端的容量的最小值 然后EK就行 #include <cst ...
- UVa 11082 & 最大流的行列模型
题意: 给出一个矩阵前i行的和与前j列的和,(i∈[1,r],j属于[1,c]),每个元素ai,j∈[1,20],请你还原出这个矩阵,保证有解. SOL: 给网络流建模跪了,神一样的建图,如果我我会怎 ...
- uva 12549 最大流
思路:这题的原型题是比较经典的网络流.原型题模型就是把所有的障碍去掉. 有障碍做法还是一样的,只用将每个列和行重新划分,求最大流就行了. #include <cstring> #inclu ...
- 【网络流#5】UVA 11082 最大流
网络流题目最有意思的地方就是构图了,毕竟套模板每个人都会的 现在有一个矩阵,已知前i行元素之和a[i](1<=i<=n),前j列元素之和b[j](1<=j<=m),求一个可行的 ...
- 【网络流#4】UVA 753 最大流
最近开始刷网络流的题目了,先从紫书上的开始,这道题是P374上的,嘛,总之这道题最终还是参考了一下紫书. 中间是用了STL中map将字符串映射成编号,使用编号总比是用字符串简单的多. 超级源点S与各个 ...
- UVa 10806 & 费用流+意识流...
题意: 一张无向图,求两条没有重复的从S到T的路径. SOL: 网络流为什么屌呢..因为网络流的容量,流量,费用能对许许多多的问题进行相应的转化,然后它就非常的屌. 对于这道题呢,不是要没有重复吗?不 ...
- uva 11380(最大流+拆点)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=36707 思路:根据题意拆点建图即可. #include<io ...
随机推荐
- MYSQL序言
我写MYSQL的文章主要的原因:我发现网上关于MYSQL的文章比较少,而且很多都是参差不齐,几乎找不到可以比较全面的介绍:例如一篇文章介绍如何增删改查,却没有介绍批量新增:于是下次工作中用到的时候又要 ...
- codevs 3186 队列练习2
3186 队列练习 2 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description (此题与队列练习1相比改了2处:1加 ...
- WIN2003跳出res://C:WINDOWSsystem32mys.dll/mys.hta解决方法
出现这个问题的时候 @echo off 请将以下语句复制到记事本中,另存为后缀为.cmd的文件,并运行.当然在命令行下一句句运行也没问题. echo 正在修复,这个过程可能需要几分钟,请稍候…… ru ...
- 【转】Class.forName()用法详解
ref: http://blog.csdn.net/kaiwii/article/details/7405761 主要功能 Class.forName(xxx.xx.xx)返回的是一个类 Class. ...
- html5离线应用详摘
html5离线应用详摘 在html文件里配置如下: <html manifest=”name.manifest”> 在name.manifest文件里配置如下: CACHE MANIFES ...
- How to add EDT relation table[AX2012]
setp 1. First create New Edit. setp 2.Create New Table First Table Name is NParentRel then drag and ...
- 11g RAC R2 日常巡检--Grid
一.巡检RAC数据库 1.1列出数据库 [grid@node1 ~]$ srvctl config database racdb [grid@node1 ~]$ 1.2列出数据库的实例 [grid@n ...
- linux安装IPython四种方法
IPython是Python的交互式Shell,提供了代码自动补完,自动缩进,高亮显示,执行Shell命令等非常有用的特性.特别是它的代码补完功能,例如:在输入zlib.之后按下Tab键,IPytho ...
- Python开发【第一篇】Python基础之自定义模块和内置模块
为什么要有模块,将代码归类.模块,用一砣代码实现了某个功能的代码集合. Python中叫模块,其他语言叫类库. 类似于函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用即可,提供了代 ...
- Oracle varchar2 4000
关于oracle varchar2 官方文档的描述 VARCHAR2 Data Type The VARCHAR2 data type specifies a variable-length char ...