poj 3469
Time Limit: 15000MS | Memory Limit: 131072K | |
Total Submissions: 18120 | Accepted: 7818 | |
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 <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue> using namespace std; const int MAX_N = ;
const int INF = ( << );
int N,M;
struct Edge{ int from, to, cap, flow; };
vector<Edge> edges;
int cur[MAX_N],d[MAX_N];
vector<int> G[MAX_N];
bool vis[MAX_N]; void add_edge(int from, int to, int cap) {
edges.push_back(Edge {from, to, cap, });
edges.push_back(Edge {to, from, , });
int m = edges.size();
G[from].push_back(m - );
G[to].push_back(m - );
} bool bfs(int s,int t) { memset(vis,,sizeof(vis));
queue<int> q;
q.push(s);
d[s] = ;
vis[s] = ;
while (!q.empty()) {
int x = q.front(); q.pop();
for (int i = ; i < G[x].size(); ++i) {
Edge& e = edges[ G[x][i] ];
if (!vis[e.to] && e.cap > e.flow) {
d[e.to] = d[x] + ;
vis[e.to] = ;
q.push(e.to);
}
}
} return vis[t];
} int dfs(int x, int a, int t) {
if(x == t || a == ) return a;
int flow = ,f;
for(int& i = cur[x]; i < G[x].size(); ++i) {
Edge& e = edges[ G[x][i] ];
if(d[x] + == d[e.to] && (f = dfs(e.to,min(a,e.cap - e.flow),t)) > ) {
e.flow += f;
edges[ G[x][i] ^ ].flow -= f;
a -= f;
flow += f;
if(a == ) break; } } return flow;
} int Maxflow(int s, int t) { int flow = ;
while (bfs(s,t)) {
//printf("fuck\n");
memset(cur,,sizeof(cur));
flow += dfs(s, INF, t);
}
return flow;
}
int main()
{
//freopen("sw.in","r",stdin);
scanf("%d%d", &N, &M);
for (int i = ; i <= N; ++i) {
int a,b;
scanf("%d%d", &a, &b);
add_edge(,i,a);
add_edge(i,N + ,b);
} for (int i = ; i <= M; ++i) {
int a,b,w;
scanf("%d%d%d",&a,&b,&w);
add_edge(a,b,w);
add_edge(b,a,w);
} printf("%d\n",Maxflow(,N + ));
//cout << "Hello world!" << endl;
return ;
}
poj 3469的更多相关文章
- POJ 3469.Dual Core CPU 最大流dinic算法模板
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 24830 Accepted: 10756 ...
- poj 3469(网络流模版)
题目链接:http://poj.org/problem?id=3469 思路:终于把网络流的模版测试好了,在Dinic和Sap之间还是选择了Sap,事实证明Sap确实比Dinic效率高,在此贴出自己的 ...
- POJ 3469 Dual Core CPU(最小割)
[题目链接] http://poj.org/problem?id=3469 [题目大意] 有N个模块要在A,B两台机器上执行,在不同机器上有不同的花费 另有M个模块组(a,b),如果a和b在同一台机子 ...
- poj 3469 Dual Core CPU——最小割
题目:http://poj.org/problem?id=3469 最小割裸题. 那个限制就是在 i.j 之间连双向边. 根据本题能引出网络流中二元关系的种种. 别忘了写 if ( x==n+1 ) ...
- 【网络流#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: 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 最大流
划分成两个集合使费用最小,可以转成最小割,既最大流. //#pragma comment(linker, "/STACK:1024000000,1024000000") #incl ...
- 网络流最小割 POJ 3469
题意 2个CPU n个任务 给出在第一个 第二个运行时的花费 m 个 a b 不在同一个CPU运行的额外花费 建图 源点 -> n -> 汇点 权 a1 ...
随机推荐
- 安装使用rspec
一,安装ruby. 二,运行命令,安装rspec的gem包: gem install rspec 会看到如下的结果: Fetching: rspec-core-2.14.7.gem (100%) Fe ...
- 安装SQL Server Management Studio遇到的29506错误
首先要在IIS里把internet 信息哪项选上.然后在安装SQL Server, 在安装的时候一直报 29506错误,装了几次,不知道什么原因.谷歌了一下说是权限的问题. 很纳闷,我当然用的是管理员 ...
- [第四版]用getaddrinfo设置tcp基本连接属性
getaddrinfo getaddrinfo的一个重要功能, 很方便的构造struct sockaddr_in对象, 把繁琐的构造过程隐藏起来 getaddrinfo兼有gethostbyname和 ...
- Express实现http和https服务
一.介绍Http与Https 概念 HTTP: 超文本传输协议(Hypertext transfer protocol) 是一种详细规定了浏览器和万维网服务器之间互相通信的规则,通过因特网传送万维网文 ...
- Laravel5.1控制器小结
控制器一般存放在app\Http\Controllers目录下,所有Laravel控制器都应继承基础控制器类. 基础控制器 基础控制器例子: <?php namespace App\Http\C ...
- hdu 4198 Quick out of the Harbour
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4198 Quick out of the Harbour Description Captain Cle ...
- 横屏下的ImagePickerController
Try this way.... As per Apple Document, ImagePicker Controller never Rotate in Landscape mode. You h ...
- ExtJS MVC结构
概述 大型的应用在开发和运维上都存在着困难.应用功能的调整和开发人员的调动都会影响对项目的掌控.ExtJS4带来了一种新的应用结构.这种结构不止用于组织代码,也能有效的减少必要的代码量. 这次ExtJ ...
- 5个SQL核心
5个核心的SQL语句 1.SELECT -查询语句的逻辑处理顺序 5 SELECT <columnlist> 1 FROM <source objectlist> ...
- Kinect帮助文档翻译之一 入门
最近在玩Kinect,使用的是Unity,发现网上好像没有什么教程.自己就只有抱着英文版帮助文档啃,真是苦逼 本人英语也不好,大家将就着看吧 Kinect入门帮助 如何运行示例 1 下载并 ...