Dual Core CPU
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的更多相关文章

  1. 【LA 3487】Duopoly(图论--网络流最小割 经典题)

    题意:C公司有一些资源,每种只有1个,有A.B两个公司分别对其中一些资源进行分组竞标,每组竞标对一些资源出一个总价.问C公司的最大收益. 解法:最小割.将A公司的竞标与源点相连,B公司的与汇点相连,边 ...

  2. 【LA3487】最小割-经典模型 两种方法

    题目链接 题意:A.B两个公司要买一些资源(他们自己买的资源不会重复),一个资源只能卖给一个公司.问最大收益. simple input 部分: 54 1 //买到1就给54元 15 2 33 3 2 ...

  3. 【BZOJ 3232】圈地游戏 二分+SPFA判环/最小割经典模型

    最小割经典模型指的是“一堆元素进行选取,对于某个元素的取舍有代价或价值,对于某些对元素,选取后会有额外代价或价值”的经典最小割模型,建立倒三角进行最小割.这个二分是显然的,一开始我也是想到了最小割的那 ...

  4. Being a Hero (hdu 3251 最小割 好题)

    Being a Hero Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  5. 最小割板子题——[USACO5.4]奶牛的电信

    今天邱神给我们讲了图论,还讲了一下网络流算法.自己找了一个洛谷板子题. 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果 ...

  6. 【uva 1515】Pool construction(图论--网络流最小割 模型题)

    题意:有一个水塘,要求把它用围栏围起来,每个费用为b.其中,(#)代表草,(.)代表洞,把一个草变成洞需要费用d, 把一个洞变成草需要费用f.请输出合法方案中的最小费用. 解法:(不好理解...... ...

  7. HDU 5889 Barricade(最短路+最小割水题)

    Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  8. HDU 3657 Game(取数 最小割)经典

    Game Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  9. poj2914 Minimum Cut 全局最小割模板题

    Minimum Cut Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 8324   Accepted: 3488 Case ...

随机推荐

  1. 《名侦探柯南》动画登陆bilibili

    不管你看没看过.喜不喜欢,也一定听说过<名侦探柯南>这部动画,它和<火影>.<海贼王>几部动画陪伴了一代人成长的道路,而且<名侦探柯南>还是这几部动画中 ...

  2. MySQL根据业务场景归纳常用SQL语句

    素材表数据:user[{"id":1,"name":"x"},{"id":2,"name":&quo ...

  3. 前端存储 (5) - service worker 离线存储

    service worker 离线存储 简介: 一般的网站 在我们无法访问的 时候 一般 回出现 如下 该网页无法访问 service worker 构建的网站不会出现这个错误,因为所有的 请求都是先 ...

  4. Codeforce 1102 C. Doors Breaking and Repairing

    Descirbe You are policeman and you are playing a game with Slavik. The game is turn-based and each t ...

  5. git的下载与安装

    Git的下载地址:https://git-scm.com/download/win 第一步:根据自己电脑的位数下载Git 第二步:下载安装包,放到指定的文件夹 第三步:更换路径安装Git(也可以放在C ...

  6. POJ3734(矩阵快速幂)

    \(假设现在到第i个积木\) \(红绿恰都是偶数a种方案,恰都是奇数为b种方案,一奇一偶为c种方案\) \(由此考虑i+1个积木的情况\) Ⅰ.一奇一偶的方案 \(如果第i层恰是奇数的情况,那么本次只 ...

  7. 给大家发个Python和Django的福利吧,不要钱的那种~~~

    前言一: 这篇是一个发放福利的文章,但是发放之前,我还是想跟大家聊聊我为什么要发这样的福利. 我第一份工作是做的IT桌面支持,日常工作就是给同事修修电脑.装装软件.开通账号.维护内部系统之类的基础工作 ...

  8. 如何写好、管好单元测试?基于Roslyn+CI分析单元测试,严控产品提测质量

    上一篇文章中,我们谈到了通过Roslyn进行代码分析,通过自定义代码扫描规则,将有问题的代码.不符合编码规则的代码扫描出来,禁止签入,提升团队的代码质量. .NET Core技术研究-通过Roslyn ...

  9. SAP ME31K SUBOBJECT_NOT_FOUND

    SUBOBJECT_NOT_FOUND 在使用BAPI:BAPI_CONTRACT_CREATE创建协议时报错, 错误位置在此处,子对象没找到 GOOGLE到相关解决方案 事务代码:SLG0 新增对象 ...

  10. Neo4j填坑记录-Neo4jClient建立节点、建立关系相关

    最近一个项目需要用到知识图谱,选用了neo4j图数据库,在这过程中遇到几个坑,记录一下 1.无法登录,疯狂提示“WebSocket connection failure. Due to securit ...