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+. ...
随机推荐
- ElasticSearch 环境安装
1)官网安装教程: http://www.elasticsearch.org/guide/reference/setup/installation/ 2)简单安装: http://log.medc ...
- 剑指offer题目练习一
看见了一道二维数组找数的题,已排好序的数组(从左至右从上到下,都是由小变大的)让找数,瞬间就出思路了,并没有必要去看他的解释,两次二分就搞定了. #include<cstdio> #inc ...
- MySQL权限管理创建帐户
权限管理 1.创建账号 # 本地账号 create user 'egon1'@'localhost' identified by '123'; # mysql -uegon1 -p123 # 远程帐号 ...
- P2580 于是他错误的点名开始了(trie)
P2580 于是他错误的点名开始了 题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 他会一边搓炉石一边点名以至于有一天他连续点到了某个同学两次,然后正好被路过的校长发现了然后就是一顿欧拉欧拉欧拉 ...
- 1.bootstrap的HTML文件编写规范
1.head标签里面的内容 <!DOCTYPE html> <html lang="zh-cn"> <head> <!-- 页面编码 -- ...
- [转] PHP在不同页面之间传值的三种常见方式
转自: http://my.oschina.net/jiec/blog/196153 一. POST传值 post传值是用于html的<form>表单跳转的方法,很方便使用.例如: < ...
- 《Cracking the Coding Interview》——第4章:树和图——题目7
2014-03-19 04:48 题目:最近公共父节点问题. 解法1:Naive算法,先对其高度,然后一层一层往上直到找到结果. 代码: // 4.7 Least Common Ancestor // ...
- 安装LoadRunner11报缺少vc2005_sp1_with_atl_fix_redist的错误
找到安装程序自带的lrunner\Chs\prerequisites\vc2005_sp1_redist,双击运行vcredist_x86.exe,再重新安装LoadRunner即可成功. 参考资料: ...
- Python 3基础教程6-for循环语句
本文介绍另外一种循环语句,for循环,直接看例子. 用for实现打印1到9的数字. 方法一:写入一个列表,然后遍历列表 # 这里介绍 for循环# 打印1到9 exampleList = [1,2,3 ...
- 一个初学者的辛酸路程-前端js
内容回顾: 1.CSS的基本概念: 层叠样式表. 2.CSS的三种书写方式 ① 行内样式 <div style="color: red;">sdfdsf</div ...