题目链接

好裸的题.......

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

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define mem(a) memset(a, 0, sizeof(a))
  4. const int maxn = 3e5+;
  5. int head[maxn*], s, t, num, q[maxn*], dis[maxn];
  6. struct node
  7. {
  8. int to, nextt, c;
  9. }e[maxn*];
  10. void init() {
  11. mem1(head);
  12. num = ;
  13. }
  14. void add(int u, int v, int c) {
  15. e[num].to = v; e[num].nextt = head[u]; e[num].c = c; head[u] = num++;
  16. }
  17. int bfs() {
  18. int u, v, st = , ed = ;
  19. mem(dis);
  20. dis[s] = ;
  21. q[ed++] = s;
  22. while(st<ed) {
  23. u = q[st++];
  24. for(int i = head[u]; ~i; i = e[i].nextt) {
  25. v = e[i].to;
  26. if(e[i].c&&!dis[v]) {
  27. dis[v] = dis[u]+;
  28. if(v == t)
  29. return ;
  30. q[ed++] = v;
  31. }
  32. }
  33. }
  34. return ;
  35. }
  36. int dfs(int u, int limit) {
  37. if(u == t)
  38. return limit;
  39. int cost = ;
  40. for(int i = head[u]; ~i; i = e[i].nextt) {
  41. int v = e[i].to;
  42. if(e[i].c&&dis[u] == dis[v]-) {
  43. int tmp = dfs(v, min(limit-cost, e[i].c));
  44. if(tmp>) {
  45. e[i].c -= tmp;
  46. e[i^].c += tmp;
  47. cost += tmp;
  48. if(cost == limit)
  49. break;
  50. } else {
  51. dis[v] = -;
  52. }
  53. }
  54. }
  55. return cost;
  56. }
  57. int dinic() {
  58. int ans = ;
  59. while(bfs()) {
  60. ans += dfs(s, inf);
  61. }
  62. return ans;
  63. }
  64. int main()
  65. {
  66. int n, m, x, y, z;
  67. while(~scanf("%d%d", &n, &m)) {
  68. s = , t = n+;
  69. init();
  70. for(int i = ; i<=n; i++) {
  71. scanf("%d%d", &x, &y);
  72. add(s, i, x);
  73. add(i, s, );
  74. add(i, t, y);
  75. add(t, i, );
  76. }
  77. while(m--) {
  78. scanf("%d%d%d", &x, &y, &z);
  79. add(x, y, z);
  80. add(y, x, z);
  81. }
  82. printf("%d\n", dinic());
  83. }
  84. }

poj 3469 Dual Core CPU 最小割的更多相关文章

  1. poj 3469 Dual Core CPU——最小割

    题目:http://poj.org/problem?id=3469 最小割裸题. 那个限制就是在 i.j 之间连双向边. 根据本题能引出网络流中二元关系的种种. 别忘了写 if ( x==n+1 ) ...

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

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

  3. 【网络流#8】POJ 3469 Dual Core CPU 最小割【ISAP模板】 - 《挑战程序设计竞赛》例题

    [题意]有n个程序,分别在两个内核中运行,程序i在内核A上运行代价为ai,在内核B上运行的代价为bi,现在有程序间数据交换,如果两个程序在同一核上运行,则不产生额外代价,在不同核上运行则产生Cij的额 ...

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

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

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

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

  6. POJ 3469 Dual Core CPU Dual Core CPU

    Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 23780   Accepted: 10338 Case Time Lim ...

  7. POJ 3469(Dual Core CPU-最小割)[Template:网络流dinic V2]

    Language: Default Dual Core CPU Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 19321 ...

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

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

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

    (点击此处查看原题) 题意介绍 在一个由核A和核B组成的双核CPU上执行N个任务,任务i在核A上执行,花费Ai,在核B上执行,花费为Bi,而某两个任务之间可能需要进数据交互,如果两个任务在同一个核上执 ...

随机推荐

  1. Sql Server 服务器名称\实例名称 无法连接 Server Name\Instance Name

      解决步骤: 1:  Sql Server是否已经启动. 2:  检查Sql Server服务器是否开启TCP/IP协议. 侦听的默认端口为1433          3:     ping 数据库 ...

  2. php7 install memcached extension

    #download source code package from git $ git clone https://github.com/php-memcached-dev/php-memcache ...

  3. Android setOnTouchListener识别滑动手势

    setOnTouchListener(new OnTouchListener() { private float startX, startY, offsetX, offsetY; @Override ...

  4. 修改host文件的P处理

    notepad C:\WINDOWS\system32\drivers\etc\hosts 用文档创建hosts文件,添加上面代码.把文件后缀修改为 .bat 就不用每次很麻烦的查找host文件了.

  5. iMac Termanel命令まとめ

    1.mac环境下命令的使用ls -l -a   列出指定目录下文件           -l 显示文件的详细信息           -a 显示目录下所有文件(包括隐藏文件)           -d ...

  6. php对xml的处理

    $paymentResult  = $ips='<Ips><GateWayRsp><head><ReferenceID></ReferenceID ...

  7. hdu 5726 GCD 倍增+ 二分

    题目链接 给n个数, 定义一个运算f[l,r] = gcd(al, al+1,....ar). 然后给你m个询问, 每次询问给出l, r. 求出f[l, r]的值以及有多少对l', r' 使得f[l, ...

  8. Hash算法原理理解

    我们有很多的小猪,每个的体重都不一样,假设体重分布比较平均(我们考虑到公斤级别),我们按照体重来分,划分成100个小猪圈. 然后把每个小猪,按照体重赶进各自的猪圈里,记录档案. 好了,如果我们要找某个 ...

  9. IP校验和

    #include <stdio.h> #include <unistd.h> #include <linux/if_ether.h> #include <li ...

  10. JS---DOM概述

    DOM DOM:文档对象模型document object model DOM三层模型: DOM1:将HTML文档封装成对象 DOM2:将XML文档封装成对象 DOM3:将XML文档封装成对象 DOM ...