POJ 3469 Dual Core CPU Dual Core CPU
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) . Output Output only one integer, the minimum total cost. Sample Input
Sample Output
Source POJ Monthly--2007.11.25, Zhou Dong
|
[Submit] [Go Back] [Status] [Discuss]
- #include <cstdio>
- #include <cstring>
- inline char nextChar(void)
- {
- static const int siz = << ;
- static char buf[siz];
- static char *hd = buf + siz;
- static char *tl = buf + siz;
- if (hd == tl)
- fread(hd = buf, , siz, stdin);
- return *hd++;
- }
- inline int nextInt(void)
- {
- register int ret = ;
- register bool neg = false;
- register char bit = nextChar();
- for (; bit < ; bit = nextChar())
- if (bit == '-')neg ^= true;
- for (; bit > ; bit = nextChar())
- ret = ret * + bit - '';
- return neg ? -ret : ret;
- }
- const int inf = 2e9;
- const int maxn = ;
- const int maxm = ;
- int n, m;
- int s, t;
- int hd[maxn];
- int to[maxm];
- int nt[maxm];
- int fl[maxm];
- inline void addEdge(int u, int v, int f)
- {
- static int tot = ;
- static bool init = true;
- if (init)
- memset(hd, -, sizeof(hd)), init = false;
- nt[tot] = hd[u]; to[tot] = v; fl[tot] = f; hd[u] = tot++;
- nt[tot] = hd[v]; to[tot] = u; fl[tot] = ; hd[v] = tot++;
- }
- int dep[maxn];
- inline bool bfs(void)
- {
- static int que[maxn];
- static int head, tail;
- memset(dep, , sizeof(dep));
- que[head = ] = s, dep[s] = tail = ;
- while (head != tail)
- {
- int u = que[head++], v;
- for (int i = hd[u]; ~i; i = nt[i])
- if (fl[i] && !dep[v = to[i]])
- dep[que[tail++] = v] = dep[u] + ;
- }
- return dep[t];
- }
- int cur[maxn];
- inline int min(int a, int b)
- {
- return a < b ? a : b;
- }
- int dfs(int u, int f)
- {
- if (!f || u == t)
- return f;
- int used = , flow, v;
- for (int i = cur[u]; ~i; i = nt[i])
- if (fl[i] && dep[v = to[i]] == dep[u] + )
- {
- flow = dfs(v, min(fl[i], f - used));
- used += flow;
- fl[i] -= flow;
- fl[i^] += flow;
- if (fl[i])
- cur[u] = i;
- if (used == f)
- return f;
- }
- if (!used)
- dep[u] = ;
- return used;
- }
- inline int maxFlow(void)
- {
- int maxFlow = , newFlow;
- while (bfs())
- {
- memcpy(cur, hd, sizeof(hd));
- while (newFlow = dfs(s, inf))
- maxFlow += newFlow;
- }
- return maxFlow;
- }
- signed main(void)
- {
- n = nextInt();
- m = nextInt();
- s = , t = n + ;
- for (int i = ; i <= n; ++i)
- {
- int ai = nextInt();
- int bi = nextInt();
- addEdge(s, i, ai);
- addEdge(i, t, bi);
- }
- for (int i = ; i <= m; ++i)
- {
- int x = nextInt();
- int y = nextInt();
- int w = nextInt();
- addEdge(x, y, w);
- addEdge(y, x, w);
- }
- printf("%d\n", maxFlow());
- }
@Author: YouSiki
POJ 3469 Dual Core CPU Dual Core CPU的更多相关文章
- 使用dotnet-dump 查找 .net core 3.0 占用CPU 100%的原因
公司的产品一直紧跟 .net core 3.0 preview 不断升级, 部署到 Linux 服务器后, 偶尔会出现某个进程CPU占用100%. 由于服务部署在云上, 不能使用远程调试; 在局域网内 ...
- physical CPU vs logical CPU vs Core vs Thread vs Socket(翻译)
原文地址: http://www.daniloaz.com/en/differences-between-physical-cpu-vs-logical-cpu-vs-core-vs-thread-v ...
- 处理器核、Core、处理器、CPU区别&&指令集架构与微架构的区别&&32位与64位指令集架构说明
1.处理器核.Core.处理器.CPU的区别 严格来说"处理器核"和" Core "是指处理器内部最核心的部分,是真正的处理器内核:而"处理器&quo ...
- 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: 21453 Accepted: 9297 ...
- POJ 3469 Dual Core CPU (最小割建模)
题意 现在有n个任务,两个机器A和B,每个任务要么在A上完成,要么在B上完成,而且知道每个任务在A和B机器上完成所需要的费用.然后再给m行,每行 a,b,w三个数字.表示如果a任务和b任务不在同一个机 ...
- poj 3469 Dual Core CPU
题目描述:由于越来越多的计算机配置了双核CPU,TinySoft公司的首席技术官员,SetagLilb,决定升级他们的产品-SWODNIW.SWODNIW包含了N个模块,每个模块必须运行在某个CPU中 ...
- poj 3469 Dual Core CPU 最小割
题目链接 好裸的题....... 两个cpu分别作为源点和汇点, 每个cpu向元件连边, 权值为题目所给的两个值, 如果两个元件之间有关系, 就在这两个元件之间连边, 权值为消耗,这里的边应该是双向边 ...
- POJ 3469 Dual Core CPU(最小割)
[题目链接] http://poj.org/problem?id=3469 [题目大意] 有N个模块要在A,B两台机器上执行,在不同机器上有不同的花费 另有M个模块组(a,b),如果a和b在同一台机子 ...
随机推荐
- 炸!分享美团面试关于selenium的面试题
个人分类: 软件测试 编辑 在这个互联网技术快速迭代的时代,每个测试员都知道技术对于职业发展的重要性,那些技术好的测试员不仅薪资高,而且大多数集中在一线互联网企业工作,让人感觉非常高大上的同时,也想去 ...
- 机器学习(一):记一次k一近邻算法的学习与Kaggle实战
本篇博客是基于以Kaggle中手写数字识别实战为目标,以KNN算法学习为驱动导向来进行讲解. 写这篇博客的原因 什么是KNN kaggle实战 优缺点及其优化方法 总结 参考文献 写这篇博客的原因 写 ...
- 在 Linux 下执行安装 bin 文件
原文: http://www.linuxidc.com/Linux/2014-03/98541.htm
- React的setState分析
前端框架层出不穷,不过万变不离其宗,就是从MVC过渡到MVVM.从数据映射到DOM,angular中用的是watcher对象,vue是观察者模式,react就是state了. React通过管理状态实 ...
- Mac SpotLight无法搜索
在终端运行如下命令: sudo mdutil -i on /
- D.王者荣耀交流协会——PSP Daily(测评人:贾男男)
D.王者荣耀交流协会——PSP Daily(测评人:贾男男) 一.基于NABCD评论作品,及改进建议 每个小组评论其他小组beta发布的作品.1.根据(不限于)NABCD评论作品的选题;2.评论作品对 ...
- 《Spring1之第九次站立会议》
<第九次站立会议> 昨天:对用C#写的视频功能进行了相关的了解. 今天:试着把用C#写的代码转换为java语言. 遇到的问题:说实话,真心不好转换,转换过程中遇到了很多问题.
- 剑指offer :从尾到头打印链表
题目描述: 输入一个链表,按链表值从尾到头的顺序返回一个ArrayList. 解题思路: 链表的遍历只能从头向尾进行,要从尾到头输出,考虑用栈.先从头到尾遍历一次链表,同时将值进栈,再清空栈,同时将值 ...
- [Elite 2008 Dec USACO]Jigsaw Puzzles
#include <iostream> #include <cstdio> #include <cstring> using namespace std; #def ...
- 二路归并排序java实现
二路归并排序:其核心思想时将问题一分为二,并递归调用一分为二方法,使问题分割到不能再分各的原子问题,然后再归并,从实现原子问题开始,层层向上归并,最终解决整体问题.即所谓“分而治之,万流归一” 二路归 ...