Dual Core CPU
Time Limit: 15000MS   Memory Limit: 131072K
Total Submissions: 25576   Accepted: 11033
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: abw. 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

Source

题目大意:一个cpu有两个核,有n个任务,m个要求,第i个任务如果用第一个核处理需要花费ai,第二个需要花费bi,对于m个要求:如果任务i和j不在同一个核上运行,则要额外花费c,求最小花费.
分析:感觉又像是匹配问题,关系比较复杂,不能用二分图来做,于是就用网络流.
          如果考虑流的意义,图比较难建,考虑最小割的意义.删掉权值和最小的边使得源点汇点不连通.为了保证每个任务只会选一个核,将A核作为源点,B核作为汇点,源点向每个任务连一条容量为A花费的边,每个任务向汇点连一条容量为B花费的边,这样如果没有m个要求的话,最小割=答案便成立.如果有要求a,b,c.则在a,b之间互相连权值为c的边.这样如果a,b用的不是同一核,删掉两条边后会因为新加的这条边而继续相连.所以最小割=答案. 
          最大流问题建模考虑答案与最大流或最小割之间的关系.
#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int maxn = ,inf = 0x7fffffff; int n,f,d,S,T,head[maxn],to[maxn],nextt[maxn],tot = ,w[maxn],ans,m;
int vis[maxn]; void add(int x,int y,int z)
{
w[tot] = z;
to[tot] = y;
nextt[tot] = head[x];
head[x] = tot++; w[tot] = ;
to[tot] = x;
nextt[tot] = head[y];
head[y] = tot++;
} bool bfs()
{
queue <int> q;
memset(vis,-,sizeof(vis));
vis[S] = ;
q.push(S);
while (!q.empty())
{
int u = q.front();
q.pop();
if (u == T)
return true;
for (int i = head[u];i;i = nextt[i])
{
int v = to[i];
if (vis[v] == - && w[i])
{
vis[v] = vis[u] + ;
q.push(v);
}
}
}
return false;
} int dfs(int u,int f)
{
int res = ;
if (u == T)
return f;
for (int i = head[u];i;i = nextt[i])
{
int v = to[i];
if (w[i] && vis[v] == vis[u] + )
{
int temp = dfs(v,min(f - res,w[i]));
res += temp;
w[i] -= temp;
w[i ^ ] += temp;
if (res == f)
return res;
}
}
if (!res)
vis[u] = -;
return res;
} void dinic()
{
while (bfs())
ans += dfs(S,inf);
} int main()
{
scanf("%d%d",&n,&m);
S = ;
T = n + ;
for (int i = ; i <= n; i++)
{
int a,b;
scanf("%d%d",&a,&b);
add(S,i,a);
add(i,T,b);
}
for (int i = ; i <= m; i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
add(a,b,c);
add(b,a,c);
}
dinic();
printf("%d\n",ans); return ;
}

poj3469 Dual Core CPU的更多相关文章

  1. 【做题】POJ3469 Dual Core CPU——第一道网络流

    刚学了Dinic就开始做题,然后就崩了. 题意:若干个任务,可以放在两个CPU中任意一个上完成,各有一定代价.其中又有若干对任务,如果它们不在同一个CPU上完成,会产生额外代价.最小化并输出代价. 一 ...

  2. POJ3469 Dual Core CPU(最小割)

    形象生动的最小割.. #include<cstdio> #include<cstring> #include<queue> #include<algorith ...

  3. POJ3469 Dual Core CPU(最小割)

    题意:给你n个模块,每个模块在A核花费为ai,在B核跑花费为bi,然后由m个任务(ai,bi,wi),表示如果ai,bi不在同一个核上跑,额外的花费为wi,求最小的花费. 一开始想的时候以为是费用流, ...

  4. poj3469 Dual Core CPU——最小割

    题目:http://poj.org/problem?id=3469 最小割水题(竟然没能1A): 代码如下: #include<iostream> #include<cstdio&g ...

  5. Dual Core CPU

    Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 20935 Accepted: 9054 Case ...

  6. poj 3469 Dual Core CPU【求最小割容量】

    Dual Core CPU Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 21453   Accepted: 9297 ...

  7. POJ 3469.Dual Core CPU 最大流dinic算法模板

    Dual Core CPU Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 24830   Accepted: 10756 ...

  8. POJ 3469 Dual Core CPU Dual Core CPU

    Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 23780   Accepted: 10338 Case Time Lim ...

  9. POJ3469:Dual Core CPU——题解

    http://poj.org/problem?id=3469 题目大意: 两个CPU,处理每个任务有不同的代价,有些对任务如果不在同一个CPU就会增加代价,求最小代价. ——————————————— ...

随机推荐

  1. Spring学习(3):Spring概述(转载)

    1. Spring是什么? Spring是一个开源的轻量级Java SE(Java 标准版本)/Java EE(Java 企业版本)开发应用框架,其目的是用于简化企业级应用程序开发. 在面向对象思想中 ...

  2. 袋鼠云旗下新公司云掣科技启航,深耕云MSP业务助推企业数字化转型

    1983年3月15日,国际消费者联盟组织将3月15日确立为国际消费者权益日. 2019年3月15日,袋鼠云举办三周年年会. 一生二,二生三,三生万物.植树节后,万物生长. 年会现场,袋鼠云宣布成立新公 ...

  3. 拉格朗日乘子法与KKT条件 && SVM中为什么要用对偶问题

    参考链接: 拉格朗日乘子法和KKT条件 SVM为什么要从原始问题变为对偶问题来求解 为什么要用对偶问题 写在SVM之前——凸优化与对偶问题 1. 拉格朗日乘子法与KKT条件 2. SVM 为什么要从原 ...

  4. Halcon如何保存仿射变换矩阵

    这里我们通过序列化来实现的,如下图,写到硬盘的HomMat2D_1内容和从硬盘里HomMat2D_2读出的内容一致,源代码在图片下方. Halcon源代码: hom_mat2d_identity (H ...

  5. Druid Monitor小记

    继上篇DruidDataSource源码分析之后 , 公司又要求做一个Druid的数据库监控 , 以及spring监控 , 研究一小时 , 总结出了一点经验 , 特此贴出来分享一下 一 . 利用Dru ...

  6. .NET导出Excel之NPOI

    前段时间研究过微软的Excel导出.table输出Excel,而它们也存在一些弊端: 1.对于微软的Excel导出存在一些弊端,如:需要安装Office软件.速度问题: 2.table输出Excel在 ...

  7. 软件工程第九周psp

    1.PSP表格 2.进度条 3.饼状图 4.折线图

  8. 【探路者】团队Alpha周贡献分数分配结果

    经本组成员商议,根据老师提供的分数,(每人携带10分进入团队,[探路者]团队7人,共计35分). 本周每位同学携带10分进入组内,7人共计70分.分数公布如下: 吴雨丹 15分 贾雅杰 12分 蔺依铭 ...

  9. lintcode-24-LFU缓存

    24-LFU缓存 LFU是一个著名的缓存算法 实现LFU中的set 和 get 样例 capacity = 3 set(2,2) set(1,1) get(2) >> 2 get(1) & ...

  10. 搜索引擎Elasticsearch,了解一下?

    ElasticSearch介绍 ElasticSearch是一个全文搜索服务器,也可以作为NoSql数据库,存储任意格式的文档和数据,同时可以做大数据的分析.ElasticSearch具有以下特点: ...