Time Limit: 15000MS   Memory Limit: 131072K
Total Submissions: 23780   Accepted: 10338
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

[Submit]   [Go Back]   [Status]   [Discuss]

解法:最小割。
源点S向每个任务连边,容量Ai。
每个任务向汇点T连边,容量Bi。
对于二元组关系(x,y),在x,y之间连双向边,容量C。
最小割就是最优的方案。
每个任务与S割开表示在A上完成,与T割开表示在B上完成。
——Lydrainbowcat
 
 #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的更多相关文章

  1. 使用dotnet-dump 查找 .net core 3.0 占用CPU 100%的原因

    公司的产品一直紧跟 .net core 3.0 preview 不断升级, 部署到 Linux 服务器后, 偶尔会出现某个进程CPU占用100%. 由于服务部署在云上, 不能使用远程调试; 在局域网内 ...

  2. 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 ...

  3. 处理器核、Core、处理器、CPU区别&&指令集架构与微架构的区别&&32位与64位指令集架构说明

    1.处理器核.Core.处理器.CPU的区别 严格来说"处理器核"和" Core "是指处理器内部最核心的部分,是真正的处理器内核:而"处理器&quo ...

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

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

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

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

  6. POJ 3469 Dual Core CPU (最小割建模)

    题意 现在有n个任务,两个机器A和B,每个任务要么在A上完成,要么在B上完成,而且知道每个任务在A和B机器上完成所需要的费用.然后再给m行,每行 a,b,w三个数字.表示如果a任务和b任务不在同一个机 ...

  7. poj 3469 Dual Core CPU

    题目描述:由于越来越多的计算机配置了双核CPU,TinySoft公司的首席技术官员,SetagLilb,决定升级他们的产品-SWODNIW.SWODNIW包含了N个模块,每个模块必须运行在某个CPU中 ...

  8. poj 3469 Dual Core CPU 最小割

    题目链接 好裸的题....... 两个cpu分别作为源点和汇点, 每个cpu向元件连边, 权值为题目所给的两个值, 如果两个元件之间有关系, 就在这两个元件之间连边, 权值为消耗,这里的边应该是双向边 ...

  9. POJ 3469 Dual Core CPU(最小割)

    [题目链接] http://poj.org/problem?id=3469 [题目大意] 有N个模块要在A,B两台机器上执行,在不同机器上有不同的花费 另有M个模块组(a,b),如果a和b在同一台机子 ...

随机推荐

  1. 详解YUV420数据格式

    原文地址:http://www.cnblogs.com/azraelly/archive/2013/01/01/2841269.html 1. YUV简介 YUV定义:分为三个分量,“Y”表示明亮度( ...

  2. mysql批量新增或者更新

    1.批量更新或者新增 1.单个新增或者更新 keyProperty新增完之后返回Id值

  3. 【转】利用telnet来进行调试Skynet

    https://blog.csdn.net/WhereIsHeroFrom/article/details/80674408

  4. 如何在静态方法或非Spring Bean中注入Spring Bean

           在项目中有时需要根据需要在自己new一个对象,或者在某些util方法或属性中获取Spring Bean对象,从而完成某些工作,但是由于自己new的对象和util方法并不是受Spring所 ...

  5. Daily Scrum (2015/10/23)

    这天晚上PM和我一起细算下来这周的确做了不少事儿.由于这天是周五,有的组员今晚有外出活动,有的组员忙了一周想休息一下.所以PM与我讨论提出今晚就布置些阅读的任务,给组员们一些自由分配的时间: 成员 今 ...

  6. 20135234mqy 实验三:敏捷开发与XP实践

    实     验    报     告 课程:Java 班级: 1352    姓名:mqy    学号:20135234 成绩:              指导教师:娄嘉鹏    实验日期:2015. ...

  7. C++:内存分区

    前言:最近正在学习有关static的知识,发觉对C++的内存分区不是很了解,上网查了很多资料,遂将这几天的学习笔记进行了简单整理,发表在这里 • 栈区(stack):主要用来存放函数的参数以及局部变量 ...

  8. dsdsd

    #include<iostream> using namespace std; #include<string.h> #define max 205 char map[max] ...

  9. JAVA对象的初始化过程

    出处:http://blog.csdn.net/andrew323/article/details/4665379 下面我们通过两个例题来说明对象的实例化过程. 例1:   编译并运行该程序会有以下输 ...

  10. Windows服务器安全配置指南

    1).系统安全基本设置 2).关闭不需要的服务 Computer Browser:维护网络计算机更新,禁用 Distributed File System: 局域网管理共享文件,不需要禁用 Distr ...