poj3469 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: 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
Source
- #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的更多相关文章
- 【做题】POJ3469 Dual Core CPU——第一道网络流
刚学了Dinic就开始做题,然后就崩了. 题意:若干个任务,可以放在两个CPU中任意一个上完成,各有一定代价.其中又有若干对任务,如果它们不在同一个CPU上完成,会产生额外代价.最小化并输出代价. 一 ...
- POJ3469 Dual Core CPU(最小割)
形象生动的最小割.. #include<cstdio> #include<cstring> #include<queue> #include<algorith ...
- POJ3469 Dual Core CPU(最小割)
题意:给你n个模块,每个模块在A核花费为ai,在B核跑花费为bi,然后由m个任务(ai,bi,wi),表示如果ai,bi不在同一个核上跑,额外的花费为wi,求最小的花费. 一开始想的时候以为是费用流, ...
- poj3469 Dual Core CPU——最小割
题目:http://poj.org/problem?id=3469 最小割水题(竟然没能1A): 代码如下: #include<iostream> #include<cstdio&g ...
- Dual Core CPU
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 20935 Accepted: 9054 Case ...
- poj 3469 Dual Core CPU【求最小割容量】
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 21453 Accepted: 9297 ...
- POJ 3469.Dual Core CPU 最大流dinic算法模板
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 24830 Accepted: 10756 ...
- POJ 3469 Dual Core CPU Dual Core CPU
Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 23780 Accepted: 10338 Case Time Lim ...
- POJ3469:Dual Core CPU——题解
http://poj.org/problem?id=3469 题目大意: 两个CPU,处理每个任务有不同的代价,有些对任务如果不在同一个CPU就会增加代价,求最小代价. ——————————————— ...
随机推荐
- leetcode- 将有序数组转换为二叉搜索树(java)
将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索树. 本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1. 示例: 给定有序数组: [-10,-3,0, ...
- MYSQL主从复制配置(整理)
MYSQL主从原理及过程 原理 Mysql的 Replication 是一个异步的复制过程(mysql5.1.7以上版本分为异步复制和半同步两种模式),从一个 Mysql instace(我们称之为 ...
- 【python 3.6】如何将list存入txt后,再读出list
今天遇到一个需求,就是将一个list文件读取后,存入一个txt配置文件.存入时,发现list文件无法直接存入,必须转为str模式. 但在读取txt时,就无法恢复成list类型来读取了(准确地说,即使强 ...
- redis rdb aof比较
Redis中数据存储模式有2种:cache-only,persistence; cache-only即只做为“缓存”服务,不持久数据,数据在服务终止后将消失,此模式下也将不存在“数据恢复”的手段,是一 ...
- __autoload 与spl_autoload_register()
PHP __autoload函数(自动载入类文件)的使用方法 作者: 字体:[增加 减小] 类型:转载 时间:2012-02-04 在使用PHP的OO模式开发系统时,通常大家习惯上将每个类的实现都 ...
- Beta周第8次Scrum会议(11/17)【王者荣耀交流协会】
一.小组信息 队名:王者荣耀交流协会 小组成员 队长:高远博 成员:王超,袁玥,任思佳,王磊,王玉玲,冉华 小组照片 今天拍照的人是王磊.因此他没有出现在照片中. 二.开会信息 时间:2017/11/ ...
- Team Work Ⅲ
Regal-Lighting团队设计 分工思考 本次大作业我的分工定位是:Unit及子类,主要设计实现建筑类的功能. 在上一篇博客我介绍了我的继承方案和接口设定,这一篇粗略的介绍一下实现部分 Defe ...
- 福大软工1816:Alpha事后诸葛
福大软工·第十一次作业-Alpha事后诸葛亮 组长博客链接 本次作业博客链接 项目Postmortem 模板 设想和目标 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描 ...
- 用javascript代码拼html
公司新来的同事说,他们是用javascript代码拼html代码的,如果要修改值,就是修改对象的属性. 交代下,我们现在都是用拼字符串的方式拼html代码的.他提到如果写在单独的javascript文 ...
- lintcode-387-最小差
387-最小差 给定两个整数数组(第一个是数组 A,第二个是数组 B),在数组 A 中取 A[i],数组 B 中取 B[j],A[i] 和 B[j]两者的差越小越好(|A[i] - B[j]|).返回 ...