拆点  将节点 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 最大流的更多相关文章

  1. uva 10330 - Power Transmission(网络流)

    uva 10330 - Power Transmission 题目大意:最大流问题. 解题思路:増广路算法. #include <stdio.h> #include <string. ...

  2. UVa 10330 - Power Transmission(最大流--拆点)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  3. UVa 10330 Power Transmission / 最大流

    最大流 这题有很多起点和终点 在取2个点(0和n+1) 作为唯一的起点和终点 此外每个点也有容量限制 建图时每条边上的容量为这条边和2个端的容量的最小值 然后EK就行 #include <cst ...

  4. UVa 11082 & 最大流的行列模型

    题意: 给出一个矩阵前i行的和与前j列的和,(i∈[1,r],j属于[1,c]),每个元素ai,j∈[1,20],请你还原出这个矩阵,保证有解. SOL: 给网络流建模跪了,神一样的建图,如果我我会怎 ...

  5. uva 12549 最大流

    思路:这题的原型题是比较经典的网络流.原型题模型就是把所有的障碍去掉. 有障碍做法还是一样的,只用将每个列和行重新划分,求最大流就行了. #include <cstring> #inclu ...

  6. 【网络流#5】UVA 11082 最大流

    网络流题目最有意思的地方就是构图了,毕竟套模板每个人都会的 现在有一个矩阵,已知前i行元素之和a[i](1<=i<=n),前j列元素之和b[j](1<=j<=m),求一个可行的 ...

  7. 【网络流#4】UVA 753 最大流

    最近开始刷网络流的题目了,先从紫书上的开始,这道题是P374上的,嘛,总之这道题最终还是参考了一下紫书. 中间是用了STL中map将字符串映射成编号,使用编号总比是用字符串简单的多. 超级源点S与各个 ...

  8. UVa 10806 & 费用流+意识流...

    题意: 一张无向图,求两条没有重复的从S到T的路径. SOL: 网络流为什么屌呢..因为网络流的容量,流量,费用能对许许多多的问题进行相应的转化,然后它就非常的屌. 对于这道题呢,不是要没有重复吗?不 ...

  9. uva 11380(最大流+拆点)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=36707 思路:根据题意拆点建图即可. #include<io ...

随机推荐

  1. 转载:Github 简明教程

    如果你是一枚Coder,但是你不知道Github,那么我觉的你就不是一个菜鸟级别的Coder,因为你压根不是真正Coder,你只是一个Code搬运工. 但是你如果已经在读这篇文章了,我觉的你已经知道G ...

  2. QT 多线程程序设计【转】

    QT通过三种形式提供了对线程的支持.它们分别是,一.平台无关的线程类,二.线程安全的事件投递,三.跨线程的信号-槽连接.这使得开发轻巧的多线程Qt程序更为容易,并能充分利用多处理器机器的优势.多线程编 ...

  3. jQuery 手风琴侧边菜单

    动手做了一个简单手风琴菜单,上图: 点击 B 可收缩 C 列表,点击 C 改变自身和父节点 B 的样式,悬浮时均有不同的样式改变. 先看页面代码,列表的嵌套: <div id="men ...

  4. POJ 1285 确定比赛名次

    Problem Description 有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委 ...

  5. cpoint

    #include<iostream> #include<math.h> using namespace std; class CPoint { public: int cpoi ...

  6. mfc110ud.dll not found

    mfc110ud.dll not found while debugging vs2012 MFC application. Possible Solutions: 1) >>>&g ...

  7. Oracle 创建用户授权

    权限: create session create table unlimited tablespace connect resource dba 例: #sqlplus /nolog SQL> ...

  8. javascript框架库API入口

    underscorejs : http://learning.github.io/underscore/

  9. PHP中数组排序实例学习

    先介绍下php中用于数组排序的函数: 排序方法                           升序                             降序                 ...

  10. Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_100_CI_AS" in the equal to operation.

    ErrorMessage Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" ...