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

  1. 3 1
  2. 1 10
  3. 2 10
  4. 10 3
  5. 2 3 1000

Sample Output

  1. 13

Source

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

解法:最小割。
源点S向每个任务连边,容量Ai。
每个任务向汇点T连边,容量Bi。
对于二元组关系(x,y),在x,y之间连双向边,容量C。
最小割就是最优的方案。
每个任务与S割开表示在A上完成,与T割开表示在B上完成。
——Lydrainbowcat
 
  1. #include <cstdio>
  2. #include <cstring>
  3.  
  4. inline char nextChar(void)
  5. {
  6. static const int siz = << ;
  7.  
  8. static char buf[siz];
  9. static char *hd = buf + siz;
  10. static char *tl = buf + siz;
  11.  
  12. if (hd == tl)
  13. fread(hd = buf, , siz, stdin);
  14.  
  15. return *hd++;
  16. }
  17.  
  18. inline int nextInt(void)
  19. {
  20. register int ret = ;
  21. register bool neg = false;
  22. register char bit = nextChar();
  23.  
  24. for (; bit < ; bit = nextChar())
  25. if (bit == '-')neg ^= true;
  26.  
  27. for (; bit > ; bit = nextChar())
  28. ret = ret * + bit - '';
  29.  
  30. return neg ? -ret : ret;
  31. }
  32.  
  33. const int inf = 2e9;
  34.  
  35. const int maxn = ;
  36. const int maxm = ;
  37.  
  38. int n, m;
  39. int s, t;
  40. int hd[maxn];
  41. int to[maxm];
  42. int nt[maxm];
  43. int fl[maxm];
  44.  
  45. inline void addEdge(int u, int v, int f)
  46. {
  47. static int tot = ;
  48. static bool init = true;
  49.  
  50. if (init)
  51. memset(hd, -, sizeof(hd)), init = false;
  52.  
  53. nt[tot] = hd[u]; to[tot] = v; fl[tot] = f; hd[u] = tot++;
  54. nt[tot] = hd[v]; to[tot] = u; fl[tot] = ; hd[v] = tot++;
  55. }
  56.  
  57. int dep[maxn];
  58.  
  59. inline bool bfs(void)
  60. {
  61. static int que[maxn];
  62. static int head, tail;
  63.  
  64. memset(dep, , sizeof(dep));
  65. que[head = ] = s, dep[s] = tail = ;
  66.  
  67. while (head != tail)
  68. {
  69. int u = que[head++], v;
  70.  
  71. for (int i = hd[u]; ~i; i = nt[i])
  72. if (fl[i] && !dep[v = to[i]])
  73. dep[que[tail++] = v] = dep[u] + ;
  74. }
  75.  
  76. return dep[t];
  77. }
  78.  
  79. int cur[maxn];
  80.  
  81. inline int min(int a, int b)
  82. {
  83. return a < b ? a : b;
  84. }
  85.  
  86. int dfs(int u, int f)
  87. {
  88. if (!f || u == t)
  89. return f;
  90.  
  91. int used = , flow, v;
  92.  
  93. for (int i = cur[u]; ~i; i = nt[i])
  94. if (fl[i] && dep[v = to[i]] == dep[u] + )
  95. {
  96. flow = dfs(v, min(fl[i], f - used));
  97.  
  98. used += flow;
  99. fl[i] -= flow;
  100. fl[i^] += flow;
  101.  
  102. if (fl[i])
  103. cur[u] = i;
  104.  
  105. if (used == f)
  106. return f;
  107. }
  108.  
  109. if (!used)
  110. dep[u] = ;
  111.  
  112. return used;
  113. }
  114.  
  115. inline int maxFlow(void)
  116. {
  117. int maxFlow = , newFlow;
  118.  
  119. while (bfs())
  120. {
  121. memcpy(cur, hd, sizeof(hd));
  122.  
  123. while (newFlow = dfs(s, inf))
  124. maxFlow += newFlow;
  125. }
  126.  
  127. return maxFlow;
  128. }
  129.  
  130. signed main(void)
  131. {
  132. n = nextInt();
  133. m = nextInt();
  134.  
  135. s = , t = n + ;
  136.  
  137. for (int i = ; i <= n; ++i)
  138. {
  139. int ai = nextInt();
  140. int bi = nextInt();
  141.  
  142. addEdge(s, i, ai);
  143. addEdge(i, t, bi);
  144. }
  145.  
  146. for (int i = ; i <= m; ++i)
  147. {
  148. int x = nextInt();
  149. int y = nextInt();
  150. int w = nextInt();
  151.  
  152. addEdge(x, y, w);
  153. addEdge(y, x, w);
  154. }
  155.  
  156. printf("%d\n", maxFlow());
  157. }

@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. JUC——阻塞队列

    Queue是一个队列,而队列的主要特征是FIFO先进先出,要实现生产者与消费者模型,也可以采用队列来进行中间的缓冲读取,好处是:生产者可以一直不停歇的生产数据. BlockingQueue是Queue ...

  2. webpack3升级为webpack4

    写在前面的话:为什么要升级,因为公司目前的项目使用webpack3,但是因为是多页应用,入口估计有一百多个,开发模式下慢得不像话,修改一个文件需要十几秒才编译好,之前的解决方案是减少入口,但是要调试其 ...

  3. Memcached服务器上实现多个实例(约约问题排查)

    约约测试服上出行一个问题,司机收车失败. (1)经查看代码是null指针异常. 针对,之前,同套代码发布到华威测试服,未出现该问题,遂认定不是代码问题. (2)打印异常信息,获取null值异常的收车司 ...

  4. Web服务架构

    # Web服务架构 ### Web服务模型-- 服务提供者.服务请求者.服务注册中心,服务注册中心是一个可选的角色. 现在的Web服务不仅限于WSDL,还有RESTful. - 服务提供者.即Web服 ...

  5. Netty源码分析第5章(ByteBuf)---->第10节: SocketChannel读取数据过程

    Netty源码分析第五章: ByteBuf 第十节: SocketChannel读取数据过程 我们第三章分析过客户端接入的流程, 这一小节带大家剖析客户端发送数据, Server读取数据的流程: 首先 ...

  6. 【python 2.7】输入任意字母数字,输出其对应的莫尔斯码并播放声音

    #python 2.7 #!/usr/bin/env python # -*- coding:utf-8 -*- import os import winsound,sys,time __author ...

  7. web项目中nicedit富文本编辑器的使用

    web项目中nicedit富文本编辑器的使用 一.为什么要用富文本编辑器? 先说什么是富文本编辑器吧,普通的html中input或textarea标签只能进行简单的输入,而做不到其他的文本调整功能,甚 ...

  8. 软件工程第十周psp

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

  9. No.1001_第六次团队会议

    黯淡的一日 今天发生了很令人不爽的一件事,杜正远又被叫去实验室了.昨天界面就很难做,而且我们组人手稀缺,他的缺席让我很难做下去. 今天开会我自己没做出什么来,就加了一个群组的添加功能,同样,曾哲昊也没 ...

  10. 20162314 《Program Design & Data Structures》Learning Summary Of The Ninth Week

    20162314 2017-2018-1 <Program Design & Data Structures>Learning Summary Of The Ninth Week ...