poj 3469 Dual Core CPU 最小割
好裸的题.......
两个cpu分别作为源点和汇点, 每个cpu向元件连边, 权值为题目所给的两个值, 如果两个元件之间有关系, 就在这两个元件之间连边, 权值为消耗,这里的边应该是双向边。
- #include<bits/stdc++.h>
- using namespace std;
- #define mem(a) memset(a, 0, sizeof(a))
- const int maxn = 3e5+;
- int head[maxn*], s, t, num, q[maxn*], dis[maxn];
- struct node
- {
- int to, nextt, c;
- }e[maxn*];
- void init() {
- mem1(head);
- num = ;
- }
- void add(int u, int v, int c) {
- e[num].to = v; e[num].nextt = head[u]; e[num].c = c; head[u] = num++;
- }
- int bfs() {
- int u, v, st = , ed = ;
- mem(dis);
- dis[s] = ;
- q[ed++] = s;
- while(st<ed) {
- u = q[st++];
- for(int i = head[u]; ~i; i = e[i].nextt) {
- v = e[i].to;
- if(e[i].c&&!dis[v]) {
- dis[v] = dis[u]+;
- if(v == t)
- return ;
- q[ed++] = v;
- }
- }
- }
- return ;
- }
- int dfs(int u, int limit) {
- if(u == t)
- return limit;
- int cost = ;
- for(int i = head[u]; ~i; i = e[i].nextt) {
- int v = e[i].to;
- if(e[i].c&&dis[u] == dis[v]-) {
- int tmp = dfs(v, min(limit-cost, e[i].c));
- if(tmp>) {
- e[i].c -= tmp;
- e[i^].c += tmp;
- cost += tmp;
- if(cost == limit)
- break;
- } else {
- dis[v] = -;
- }
- }
- }
- return cost;
- }
- int dinic() {
- int ans = ;
- while(bfs()) {
- ans += dfs(s, inf);
- }
- return ans;
- }
- int main()
- {
- int n, m, x, y, z;
- while(~scanf("%d%d", &n, &m)) {
- s = , t = n+;
- init();
- for(int i = ; i<=n; i++) {
- scanf("%d%d", &x, &y);
- add(s, i, x);
- add(i, s, );
- add(i, t, y);
- add(t, i, );
- }
- while(m--) {
- scanf("%d%d%d", &x, &y, &z);
- add(x, y, z);
- add(y, x, z);
- }
- printf("%d\n", dinic());
- }
- }
poj 3469 Dual Core CPU 最小割的更多相关文章
- poj 3469 Dual Core CPU——最小割
题目:http://poj.org/problem?id=3469 最小割裸题. 那个限制就是在 i.j 之间连双向边. 根据本题能引出网络流中二元关系的种种. 别忘了写 if ( x==n+1 ) ...
- POJ 3469 Dual Core CPU (最小割建模)
题意 现在有n个任务,两个机器A和B,每个任务要么在A上完成,要么在B上完成,而且知道每个任务在A和B机器上完成所需要的费用.然后再给m行,每行 a,b,w三个数字.表示如果a任务和b任务不在同一个机 ...
- 【网络流#8】POJ 3469 Dual Core CPU 最小割【ISAP模板】 - 《挑战程序设计竞赛》例题
[题意]有n个程序,分别在两个内核中运行,程序i在内核A上运行代价为ai,在内核B上运行的代价为bi,现在有程序间数据交换,如果两个程序在同一核上运行,则不产生额外代价,在不同核上运行则产生Cij的额 ...
- poj 3469 Dual Core CPU【求最小割容量】
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 21453 Accepted: 9297 ...
- 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: 23780 Accepted: 10338 Case Time Lim ...
- POJ 3469(Dual Core CPU-最小割)[Template:网络流dinic V2]
Language: Default Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 19321 ...
- POJ 3469 Dual Core CPU(最小割)
[题目链接] http://poj.org/problem?id=3469 [题目大意] 有N个模块要在A,B两台机器上执行,在不同机器上有不同的花费 另有M个模块组(a,b),如果a和b在同一台机子 ...
- POJ - 3469 Dual Core CPU (最小割)
(点击此处查看原题) 题意介绍 在一个由核A和核B组成的双核CPU上执行N个任务,任务i在核A上执行,花费Ai,在核B上执行,花费为Bi,而某两个任务之间可能需要进数据交互,如果两个任务在同一个核上执 ...
随机推荐
- Sql Server 服务器名称\实例名称 无法连接 Server Name\Instance Name
解决步骤: 1: Sql Server是否已经启动. 2: 检查Sql Server服务器是否开启TCP/IP协议. 侦听的默认端口为1433 3: ping 数据库 ...
- php7 install memcached extension
#download source code package from git $ git clone https://github.com/php-memcached-dev/php-memcache ...
- Android setOnTouchListener识别滑动手势
setOnTouchListener(new OnTouchListener() { private float startX, startY, offsetX, offsetY; @Override ...
- 修改host文件的P处理
notepad C:\WINDOWS\system32\drivers\etc\hosts 用文档创建hosts文件,添加上面代码.把文件后缀修改为 .bat 就不用每次很麻烦的查找host文件了.
- iMac Termanel命令まとめ
1.mac环境下命令的使用ls -l -a 列出指定目录下文件 -l 显示文件的详细信息 -a 显示目录下所有文件(包括隐藏文件) -d ...
- php对xml的处理
$paymentResult = $ips='<Ips><GateWayRsp><head><ReferenceID></ReferenceID ...
- hdu 5726 GCD 倍增+ 二分
题目链接 给n个数, 定义一个运算f[l,r] = gcd(al, al+1,....ar). 然后给你m个询问, 每次询问给出l, r. 求出f[l, r]的值以及有多少对l', r' 使得f[l, ...
- Hash算法原理理解
我们有很多的小猪,每个的体重都不一样,假设体重分布比较平均(我们考虑到公斤级别),我们按照体重来分,划分成100个小猪圈. 然后把每个小猪,按照体重赶进各自的猪圈里,记录档案. 好了,如果我们要找某个 ...
- IP校验和
#include <stdio.h> #include <unistd.h> #include <linux/if_ether.h> #include <li ...
- JS---DOM概述
DOM DOM:文档对象模型document object model DOM三层模型: DOM1:将HTML文档封装成对象 DOM2:将XML文档封装成对象 DOM3:将XML文档封装成对象 DOM ...