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 3 1 Sample Output 13 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在同一台机子 ...
随机推荐
- 一个可以自由存取的onedriver
https://cittedu-my.sharepoint.com/personal/jostin_5gd_me/Documents/jostin
- 【树莓派】crontab的两个问题
1,/var/log下面,没有cron.log日志 root@raspberrypi:/# nano /etc/rsyslog.conf …… …… ############### #### RULE ...
- MyBatis思维导图
1.初识框架技术 2.搭建MyBatis环境 3.掌握MyBatis的核心API 4.掌握MyBatis的核心配置文件:主要用于配置数据库连接和MyBatis运行时所需的各种特性 5.掌握SQL映射文 ...
- shutdown命令详解
基础命令学习目录 原文链接:http://www.cnblogs.com/qlqwjy/p/7746364.html 我 们在操作Linux v/服务器的时候肯定会有需要重启系统,或者关闭系统等操作. ...
- 团队博客作业Week1 --- 团队成员简介
团队博客作业Week1 团队作业1 我们团队是一个以功能团队模式组建而成的团队,我们总共有5位队员,分别是:李剑锋.陈谋.卢惠明.潘成鼎.仉伯龙. 中间的那位就是李剑锋,我们的PM(项目经理).性格热 ...
- [BUAA OO]第三次博客作业
OO第三次博客作业 1. 规格化设计的发展 我认为,规格化设计主要源自于软件设计的两次危机.第一次是由于大量存在的goto语句,让当时被广泛应用的面向过程式的编程语言臃肿不堪,在逻辑性上与工程规模上鱼 ...
- 20172325『Java程序设计』课程 结对编程练习_四则运算第二周阶段总结
20172325『Java程序设计』课程 结对编程练习_四则运算第二周阶段总结 结对伙伴 学号:20172306 姓名:刘辰 结对伙伴博客链接 刘辰同学对编程的积极程度很高,并且在编程能力上很不错,有 ...
- 20162327WJH第二次实验——树
20162327WJH第一次实验--线性结构 实 验 报 告 实 验 报 告 课程:程序设计与数据结构 班级: 1623 姓名: 王旌含 学号:20162327 成绩: 指导教师:娄嘉鹏 王志强 实验 ...
- youi软件测试计划
beta版本中,我们将重视软件开发中的测试. 我们的软件是需要测试的,不测试怎么知道好与不好呢?有的程序不测试甚至都不能运行-- 我们的目标呢:就是经过测试之后软件的质量得到有效的保证.不管什么情况都 ...
- servlet几个常用的方法
servlet继承了HTTPServlet所以可以重写父类的方法,下面一 一介绍方法Dopost DoGet 比较常用不再介绍. 一.Init(),和Init(ServletConfig config ...