UVA 10330 Power Transmission
题意:懒得打了。LUCKY CAT 里有 http://163.32.78.26/homework/q10330.htm
第一个网络流题目。每个节点都有一个容量值。需要拆点。拆成i - > i + N 边权为容量值
另外注意B个点 连接方式:s - 集合B
D个点 链接方式 集合D + N -> t汇点
其他看处理就好
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
#define MAXN 250
const int INF = 0x3f3f3f3f ;
int flow[MAXN][MAXN],c[MAXN][MAXN];
int p[MAXN];
int N,M,B,D,src,tag;
void read()
{
memset(c,,sizeof(c));
src = ; tag = * N + ;
for (int i = ; i <= N; i++)
{
int tmp;
scanf("%d",&tmp);
c[i][i + N] = tmp;
}
scanf("%d",&M);
for (int i = ; i <= M; i++)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
c[u + N][v] = w;
}
scanf("%d%d",&B,&D);
for (int i = ; i <= B; i++)
{
int tmp;
scanf("%d",&tmp);
c[][tmp] = INF;
}
for (int i = ; i <= D; i++)
{
int tmp;
scanf("%d",&tmp);
c[tmp + N][tag] = INF;
}
}
int Edmonds_karp(int src,int tag)
{
memset(flow,,sizeof(flow));
int ans = ;
queue<int>q;
while (!q.empty()) q.pop();
int a[MAXN];
while (true)
{
memset(a,,sizeof(a));
a[src] = INF;
q.push(src);
while (!q.empty())
{
int u = q.front(); q.pop();
for (int v = ; v <= tag; v++)
if (!a[v] && c[u][v] > flow[u][v])
{
p[v] = u;
q.push(v);
a[v] = min(a[u],c[u][v] - flow[u][v]);
}
}
if (a[tag] == ) break;
for (int u = tag; u != src; u = p[u])
{
flow[p[u]][u] += a[tag];
flow[u][p[u]] -= a[tag];
}
ans += a[tag];
}
return ans;
}
int main()
{
//freopen("sample.txt","r",stdin);
while (scanf("%d",&N)!=EOF)
{
read();
printf("%d\n",Edmonds_karp(src,tag));
}
return ;
}
UVA 10330 Power Transmission的更多相关文章
- 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 ...
- 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 11149.Power of Matrix-矩阵快速幂倍增
Power of Matrix UVA - 11149 代码: #include <cstdio> #include <cstring> #include < ...
- UVa 11149 Power of Matrix(倍增法、矩阵快速幂)
题目链接: 传送门 Power of Matrix Time Limit: 3000MS Description 给一个n阶方阵,求A1+A2+A3+......Ak. 思路 A1+A2+. ...
随机推荐
- poj 2579 中位数问题 查找第K大的值
题意:对列数X计算∣Xi – Xj∣组成新数列的中位数. 思路:双重二分搜索 对x排序 如果某数大于 mid+xi 说明在mid后面,这些数的个数小于 n/2 的话说明这个中位数 mid 太大 反之太 ...
- mysql学习第二天函数
-- 1.绝对值 select abs(-1)from dual -- 2.求平方根select sqrt(6)from dual -- 3.圆周率select pi()from dual -- 4. ...
- Myeclipse代码格式化的样式和保存自动格式化
第一种方法:下载格式化代码样式文件,参考这位老兄的方法(包含了保存自动格式化):http://blog.csdn.net/u010028869/article/details/49780515 下 ...
- python里面list()函数
1. list() 方法用于将元组转换为列表. 元组与列表是非常类似的,区别在于元组的元素值不能修改,元组是放在括号中,列表是放于方括号中. 2. python里面的变量不用提前声明.
- java和c/c++
写c/c++的人,羡慕java可以自己管理内存 写java的人,羡慕c/c++没有gc问题
- ICG-智能代码生成器.(权限控制.融入平台).(表单引擎).(最低兼容IE8)
请下拉滚动条... 代码生成器.附带客户端代码 个人平台:www.10086bank.com 界面: 1--首先是server制作界面(BS结构).直接上图: 2--点击提交生成一下文件: 各个代 ...
- 剑指Offer - 九度1520 - 树的子结构
剑指Offer - 九度1520 - 树的子结构2013-11-30 22:17 题目描述: 输入两颗二叉树A,B,判断B是不是A的子结构. 输入: 输入可能包含多个测试样例,输入以EOF结束.对于每 ...
- USACO Section2.1 Healthy Holsteins 解题报告 【icedream61】
holstein解题报告 --------------------------------------------------------------------------------------- ...
- linux下多线程断点下载工具-axel
今天要下载一下14G左右的文件,用wget约10小时,后来发现linux下有个多线程支持断点续传的下载工具axel,试了一下,下载速度大大增加. 包地址:http://pkgs.repoforge.o ...
- 【Remove Duplicates from Sorted List 】cpp
题目: 第一次刷的时候漏掉了这道题. Given a sorted linked list, delete all duplicates such that each element appear o ...