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+. ...
随机推荐
- 010---Django与Ajax
预备知识: 什么是Json? 定义:json是一种轻量级的数据交换格式. 如果我们要在不同的编程语言中传递对象,就必须把对象序列化为标准格式,比如XML,但那是以往的时代,现在大多数使用序列化为jso ...
- ansible-2
软件相关模块 rpm 和yum 的区别: rpm: redhat package manager :yum可以解决依赖关系 yum 源配置: cat /etc/yum.repos.d/epel.rep ...
- java.sql.SQLException: Field 'id' doesn't have a default value异常
在做mybatis插入的时候报了这个错误,百度了下,貌似是因为这个健没有设置值且不是自增类型的. java.sql.SQLException: Field 'id' doesn't have a de ...
- laravel5.5缓存系统
目录 1 Redis的配置 1.1 安装PRedis 1.2 配置 1.2.1 配置redis数据库 1.2.2 更改session的配置 1.2.3 更改cache配置 1.3 使用redis 2 ...
- 利用Xtrabackup搭建GTID主从复制(一主一从)
Preface I've been demonstrated how to implement a master-slave structure using mysqldump in ...
- 解决idea无法下载插件的问题
分析原因: 使用了 https 协议下载而导致的问题. 解决办法: 找到 File -> Settings -> Appearance & Behavior -> Syste ...
- selenium 使用谷歌浏览器模拟wap测试
/** * 使用谷歌浏览器模拟手机浏览器 * @param devicesName * @author xxx * 创建时间:2017-06-15,更新时间:2017-06-15 * 备注 */ pu ...
- Python全栈工程师(函数嵌套、变量作用域)
ParisGabriel 感谢 大家的支持 每天坚持 一天一篇 点个订阅 ...
- Python全栈工程师(数值类型、运算符)
ParisGabriel Python 入门基础 python的应用领域: 1.系统运维 2.网络编程(如:网络爬虫,搜索引擎,服务器编程) 3.科学计算 4.航空领域(如:卫星, ...
- 【志银】MySQL命令总结
===0-MySQL密码设置===0.1-登入和进入MySQL数据库: 0.1.1-登入MySQL数据库:C:\Users\Administrator>mysql -u用户名 -hMySQL服务 ...