Dual Core CPU
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: 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

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的更多相关文章

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

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

  2. poj 3469(网络流模版)

    题目链接:http://poj.org/problem?id=3469 思路:终于把网络流的模版测试好了,在Dinic和Sap之间还是选择了Sap,事实证明Sap确实比Dinic效率高,在此贴出自己的 ...

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

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

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

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

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

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

  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 最大流

    划分成两个集合使费用最小,可以转成最小割,既最大流. //#pragma comment(linker, "/STACK:1024000000,1024000000") #incl ...

  9. 网络流最小割 POJ 3469

    题意  2个CPU n个任务 给出在第一个 第二个运行时的花费 m  个  a  b 不在同一个CPU运行的额外花费 建图 源点 ->   n    -> 汇点 权          a1 ...

随机推荐

  1. 数组(Array),二维数组,三维数组

    数组(Array):相同类型数据的集合就叫做数组. (一)定义数组的方法: A) type[] 变量名 = new type[数组中元素的个数] 例如: int[] a = new int[10] ; ...

  2. 学习KMP算法

    int kmp(char * t,int lenT,char * pat,int lenPat){ ,posT=; int[] f=partialMatch(pat,lenPat)//获取pat字符串 ...

  3. dede 忘记密码在数据库中修改方法

    如何找回或修改dedecms后台管理员登录密码呢? 一个客户把密码忘了,找了很长一会没几个靠谱的回答,dede是使用md5加密,但是,它是显示32位md5加密码从第6位开始的20位 方法是直接修改其m ...

  4. Go语言工程结构

    Go是一门推崇软件工程理念的编程语言. Go的代码必须放在GOPATH目录下,它应该包含三个子目录: src:用于以代码包的形式组织并保存Go源码文件.应该分为三类:库源码文件.命令源码文件.测试源码 ...

  5. bootstrap bootstrapTable 分页 传值问题

    bootstrapTable 分页传值 配置项:将原始的 limit: params.limit, //页面大小  page: params.offset, //页码 改成 limit: params ...

  6. js jquery 判断IE有效方法

    jquery1.9以前 $.browser.msie jquery1.9更高版本 $.browser.msie = /msie/.test(navigator.userAgent.toLowerCas ...

  7. My First Django Project (3) - Apache set up

    Holy moly!!!!因为漏了一下斜杠,害我反复调试了2,3天,无法读取static 文件,一直找不出原因,后来在apache的error.log中发现了原因. 1. 下载了apache 2.4, ...

  8. linux 简单的DMA例程

    一个简单的使用DMA 例子 示例:下面是一个简单的使用DMA进行传输的驱动程序,它是一个假想的设备,只列出DMA相关的部分来说明驱动程序中如何使用DMA的. 函数dad_transfer是设置DMA对 ...

  9. OC-通讯录

    要求描述:用OC语言完成简易通讯录(实现增删改查)功能.(注:使用MRC) 1.创建AddressBook类. 1)使用字典作为容器,字典的Key值为分组名(姓名首字母),value值为数组,数组中存 ...

  10. Android L Camera2 API 使用实例程序汇总

    在网上发现几个使用Camera API2开发的实例程序,总结一下方便后续参考: 1.Camera2 Basic : https://github.com/googlesamples/android-C ...