poj3469 Dual Core CPU
| Time Limit: 15000MS | Memory Limit: 131072K | |
| Total Submissions: 25576 | Accepted: 11033 | |
| 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: a, b, w. 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
#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int maxn = ,inf = 0x7fffffff; int n,f,d,S,T,head[maxn],to[maxn],nextt[maxn],tot = ,w[maxn],ans,m;
int vis[maxn]; void add(int x,int y,int z)
{
w[tot] = z;
to[tot] = y;
nextt[tot] = head[x];
head[x] = tot++; w[tot] = ;
to[tot] = x;
nextt[tot] = head[y];
head[y] = tot++;
} bool bfs()
{
queue <int> q;
memset(vis,-,sizeof(vis));
vis[S] = ;
q.push(S);
while (!q.empty())
{
int u = q.front();
q.pop();
if (u == T)
return true;
for (int i = head[u];i;i = nextt[i])
{
int v = to[i];
if (vis[v] == - && w[i])
{
vis[v] = vis[u] + ;
q.push(v);
}
}
}
return false;
} int dfs(int u,int f)
{
int res = ;
if (u == T)
return f;
for (int i = head[u];i;i = nextt[i])
{
int v = to[i];
if (w[i] && vis[v] == vis[u] + )
{
int temp = dfs(v,min(f - res,w[i]));
res += temp;
w[i] -= temp;
w[i ^ ] += temp;
if (res == f)
return res;
}
}
if (!res)
vis[u] = -;
return res;
} void dinic()
{
while (bfs())
ans += dfs(S,inf);
} int main()
{
scanf("%d%d",&n,&m);
S = ;
T = n + ;
for (int i = ; i <= n; i++)
{
int a,b;
scanf("%d%d",&a,&b);
add(S,i,a);
add(i,T,b);
}
for (int i = ; i <= m; i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
add(a,b,c);
add(b,a,c);
}
dinic();
printf("%d\n",ans); return ;
}
poj3469 Dual Core CPU的更多相关文章
- 【做题】POJ3469 Dual Core CPU——第一道网络流
刚学了Dinic就开始做题,然后就崩了. 题意:若干个任务,可以放在两个CPU中任意一个上完成,各有一定代价.其中又有若干对任务,如果它们不在同一个CPU上完成,会产生额外代价.最小化并输出代价. 一 ...
- POJ3469 Dual Core CPU(最小割)
形象生动的最小割.. #include<cstdio> #include<cstring> #include<queue> #include<algorith ...
- POJ3469 Dual Core CPU(最小割)
题意:给你n个模块,每个模块在A核花费为ai,在B核跑花费为bi,然后由m个任务(ai,bi,wi),表示如果ai,bi不在同一个核上跑,额外的花费为wi,求最小的花费. 一开始想的时候以为是费用流, ...
- poj3469 Dual Core CPU——最小割
题目:http://poj.org/problem?id=3469 最小割水题(竟然没能1A): 代码如下: #include<iostream> #include<cstdio&g ...
- Dual Core CPU
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 20935 Accepted: 9054 Case ...
- 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 ...
- POJ3469:Dual Core CPU——题解
http://poj.org/problem?id=3469 题目大意: 两个CPU,处理每个任务有不同的代价,有些对任务如果不在同一个CPU就会增加代价,求最小代价. ——————————————— ...
随机推荐
- 【转】PHPCMS+PHPExcel实现后台数据导入导出功能
首先,上图之中的红色框框是没有的,我们想要给他加上,当然是要改HTML页面啦,废话,我们跟ECSHOP一样由PHP路径找模板: 看看路由原理: 首先,上图之中的红色框框是没有的,我们想要给他加上,当然 ...
- windows更改MySQL存储路径
在C:\ProgramData\MySQL\MySQL Server 5.7文件夹 my.ini是默认的配置文件.在这里我们只更改数据存储路径.不更改配置文件 1 # Path to the data ...
- Action Required: Listings Deactivated for Potential Pricing Error
Dear Seller, We are contacting you because we have detected potential pricing errors in your Amazon. ...
- 浅谈TSM概念、系统架构及技术发展
NFC作为一种近距离的无线通信技术,提供了一种更直接.更安全的现场交互解决方案.它能够允许电子设备之间进行非接触式点对点数据传输,实现数据交换.访问内容与服务.有了它,手机不再只是打电话.发短信以及上 ...
- Bracket Sequences Concatenation Problem括号序列拼接问题(栈+map+思维)
A bracket(括号) sequence is a string containing only characters "(" and ")".A regu ...
- SQLSERVER 根据身份证号码 往出生年月日 赋值
update CREW_SailorInfo set DT_DOB= ( case then , ) then , ) else null end) 注:此问题仅供参考 如有疑问 请加QQ群18153 ...
- 王者荣耀交流协会final发布版本控制报告
二次开发软件说明文档 Dec 6 纠正饼状图点击选择PSP文件无效. 添加饼状图丢失的代码. submit the files that last night I forgot. add shurum ...
- 获取Class实例的三种方式
方式一: 通过类.枚举.接口.注解.数组类型.原生类型的名称.class package com.rong.test; public class TestClass { public static ...
- 树莓派无显示器、无网线,优盘(U盘)启动,远程桌面
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:树莓派无显示器.无网线,优盘(U盘)启动,远程桌面 本文地址:http://techi ...
- freemarker中空值 null的处理 ?exists ?if_exists ?default(“”)
exists:由空值测试运算符的引入,它被废弃了. exp1?exists 和 exp1??是一样的, ( exp1)?exists 和(exp1)??也是一样的. if_exists:由默认值运算符 ...