最小割经典题(两个点依附在一起的情况)poj3469
Time Limit: 15000MS | Memory Limit: 131072K | |
Total Submissions: 25099 | Accepted: 10866 | |
Case Time Limit: 5000MS |
Description
As more and more computers are equipped with dual core CPU, SetagLilb, the Chief Technology Officer of TinySoft Corporation, decided to update their famous product - SWODNIW.
The routine consists of N modules, and each of them should run in a certain core. The costs for all the routines to execute on two cores has been estimated. Let's define them as Ai and Bi. Meanwhile, M pairs of modules need to do some data-exchange. If they are running on the same core, then the cost of this action can be ignored. Otherwise, some extra cost are needed. You should arrange wisely to minimize the total cost.
Input
There are two integers in the first line of input data, N and M (1 ≤ N ≤ 20000, 1 ≤ M ≤ 200000) .
The next N lines, each contains two integer, Ai and Bi.
In the following M lines, each contains three integers: a, b, w. The meaning is that if module a and module b don't execute on the same core, you should pay extra w dollars for the data-exchange between them.
Output
Output only one integer, the minimum total cost.
Sample Input
- 3 1
- 1 10
- 2 10
- 10 3
- 2 3 1000
Sample Output
- 13
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- using namespace std;
- const int N=;
- int head[N],tot,S,T;
- int q[N],dis[N],n,m;
- int mp[N][];
- struct node
- {
- int next,v,w;
- } e[N*];
- void add(int u,int v,int w)
- {
- e[tot].v=v;
- e[tot].w=w;
- e[tot].next=head[u];
- head[u]=tot++;
- }
- bool bfs()
- {
- memset(dis,-,sizeof(dis));
- dis[S]=;
- int l=,r=;
- q[r++]=S;
- while(l<r)
- {
- int u=q[l++];
- for(int i=head[u]; ~i; i=e[i].next)
- {
- int v=e[i].v;
- if(dis[v]==-&&e[i].w>)
- {
- q[r++]=v;
- dis[v]=dis[u]+;
- if(v==T) return true;
- }
- }
- }
- return false;
- }
- int dfs(int s,int low)
- {
- if(s==T||!low) return low;
- int ans=low,a;
- for(int i=head[s]; ~i; i=e[i].next)
- {
- if(e[i].w>&&dis[e[i].v]==dis[s]+&&(a=dfs(e[i].v,min(e[i].w,ans))))
- {
- e[i].w-=a;
- e[i^].w+=a;
- ans-=a;
- if(!ans) return low;
- }
- }
- if(low==ans) dis[s]=-;
- return low-ans;
- }
- int main()
- {
- scanf("%d%d",&n,&m);S=,T=n+;
- memset(head,-,sizeof(head));
- tot=;
- int x,y,u,v,w;
- for(int i=;i<=n;++i) {
- scanf("%d%d",&x,&y);
- add(S,i,x);add(i,S,);
- add(i,T,y);add(T,i,);
- }
- for(int i=;i<=m;++i) {
- scanf("%d%d%d",&u,&v,&w);
- add(u,v,w);
- add(v,u,w);
- }
- int ans=;
- while(bfs()) ans+=dfs(S,);
- printf("%d\n",ans);
- }
最小割经典题(两个点依附在一起的情况)poj3469的更多相关文章
- 【LA 3487】Duopoly(图论--网络流最小割 经典题)
题意:C公司有一些资源,每种只有1个,有A.B两个公司分别对其中一些资源进行分组竞标,每组竞标对一些资源出一个总价.问C公司的最大收益. 解法:最小割.将A公司的竞标与源点相连,B公司的与汇点相连,边 ...
- 【LA3487】最小割-经典模型 两种方法
题目链接 题意:A.B两个公司要买一些资源(他们自己买的资源不会重复),一个资源只能卖给一个公司.问最大收益. simple input 部分: 54 1 //买到1就给54元 15 2 33 3 2 ...
- 【BZOJ 3232】圈地游戏 二分+SPFA判环/最小割经典模型
最小割经典模型指的是“一堆元素进行选取,对于某个元素的取舍有代价或价值,对于某些对元素,选取后会有额外代价或价值”的经典最小割模型,建立倒三角进行最小割.这个二分是显然的,一开始我也是想到了最小割的那 ...
- Being a Hero (hdu 3251 最小割 好题)
Being a Hero Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 最小割板子题——[USACO5.4]奶牛的电信
今天邱神给我们讲了图论,还讲了一下网络流算法.自己找了一个洛谷板子题. 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果 ...
- 【uva 1515】Pool construction(图论--网络流最小割 模型题)
题意:有一个水塘,要求把它用围栏围起来,每个费用为b.其中,(#)代表草,(.)代表洞,把一个草变成洞需要费用d, 把一个洞变成草需要费用f.请输出合法方案中的最小费用. 解法:(不好理解...... ...
- HDU 5889 Barricade(最短路+最小割水题)
Barricade Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- HDU 3657 Game(取数 最小割)经典
Game Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- poj2914 Minimum Cut 全局最小割模板题
Minimum Cut Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 8324 Accepted: 3488 Case ...
随机推荐
- 浅析Java三大特性封装、继承、多态,及作业分析
前言 本次博客衔接上次博客,作为这一阶段Java学习的分析.上一篇博客着重介绍了Java的OO编程思维,面向对象与面向过程的区别.本篇博客重心在Java的三大技术特性,附带作业分析. Java三大特性 ...
- Eclipse Collections:让Java Streams更上一层楼
\ 关键要点 \\ Eclipse Collections是一个高性能的Java集合框架,为原生JDK集合增加了丰富的功能.\\t Streams是JDK的一个非常受欢迎的功能,但它缺少了一些特性,严 ...
- RHEL6 搭建 keepalived + lvs/DR 集群
搭建 keepalived + lvs/DR 集群 使用Keepalived为LVS调度器提供高可用功能,防止调度器单点故障,为用户提供Web服务: LVS1调度器真实IP地址为192.168.4. ...
- JVM调优方法笔记
1.性能工具介绍 jvisualvm jmap jstat jstack/threaddump jprofiler jmeter 2.性能调优4步骤 重现问题 定位问题 模拟问题 解决问题 http: ...
- Nginx模块开发(2)————下载文件
Nginx的HTTP模块下载文件和传送缓冲区的字符串差不多,只需将文件标志置为1即可,我转送的文件是mp3的,所以HTTP的那个mine 类型要写为audio/mp3,二话不说了,贴代码,代码和之前那 ...
- python3yupython2的差别
1.长整型 # python2中才有长整型概念,python3中只有整形一说 # 定义方法:变量名=整数+l (小写L) #python2环境下 >>> a=123456789123 ...
- docker批量删除本地镜像和容器
长时间运行docker,每次只用docker kill去停止容器,但是从没删除过本地镜像,导致有上百个镜像在占用内存. 1.批量停止容器 docker container stop $(docker ...
- spark系列-7、spark调优
官网说明:http://spark.apache.org/docs/2.1.1/tuning.html#data-serialization 一.JVM调优 1.1.Java虚拟机垃圾回收调优的背景 ...
- 学习笔记之MySQL的使用
什么是数据库? 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库. 每个数据库都有一个或多个不同的 API 用于创建,访问,管理,搜索和复制所保存的数据. 我们也可以将数据存储在文 ...
- Flutter 粘合剂CustomScrollView控件
老孟导读:快乐的51假期结束了,切换为努力模式,今天给大家分享CustomScrollView组件,此组件在以后的项目中会经常用到,CustomScrollView就像一个粘合剂,将多个组件粘合在一起 ...