【最小割】POJ-3469 Dual Core CPU
来源:互联网 发布:知乎段子集锦 编辑:程序博客网 时间:2024/05/16 17:21
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 11 102 1010 32 3 1000
Sample Output
13
/*ID: j.sure.1PROG:LANG: C++*//****************************************/#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>#include <stack>#include <queue>#include <vector>#include <map>#include <string>#include <climits>#include <iostream>#define LL long longusing namespace std;const int INF = 0x3f3f3f3f;/****************************************/const int N = 22222, M = 4*N+4e5;int n, m, tot, head[N], cur[N], lev[N], q[N], s[N], S, T;struct Node {int u, v, cap;int next;}edge[M];void init(){tot = 0; memset(head, -1, sizeof(head));}void add(int u, int v, int c){edge[tot].u = u; edge[tot].v = v; edge[tot].cap = c;edge[tot].next = head[u]; head[u] = tot++;}bool bfs(){int fron = 0, rear = 0;memset(lev, -1, sizeof(lev));lev[S] = 0; q[rear++] = S;while(fron < rear) {int u = q[fron%N]; fron++;for(int i = head[u]; i != -1; i = edge[i].next) {int v = edge[i].v;if(edge[i].cap && lev[v] == -1) {lev[v] = lev[u] + 1;q[rear%N] = v; rear++;if(v == T) return true;}}}return false;}int Dinic(){int ret = 0;while(bfs()) {memcpy(cur, head, sizeof(head));int u = S, top = 0;while(1) {if(u == T) {int mini = INF, loc;for(int i = 0; i < top; i++) {if(mini > edge[s[i]].cap) {mini = edge[s[i]].cap;loc = i;}}for(int i = 0; i < top; i++) {edge[s[i]].cap -= mini;edge[s[i]^1].cap += mini;}ret += mini;top = loc;u = edge[s[top]].u;}int &i = cur[u];for(; i != -1; i = edge[i].next) {int v = edge[i].v;if(edge[i].cap && lev[v] == lev[u] + 1) break;}if(i != -1) {s[top++] = i;u = edge[i].v;}else {if(!top) break;lev[u] = -1;u = edge[s[--top]].u;}}}return ret;}int main(){#ifdef J_Sure//freopen("000.in", "r", stdin);//freopen(".out", "w", stdout);#endifscanf("%d%d", &n, &m);init();S = 0; T = n+1;int A, B;for(int i = 1; i <= n; i++) {scanf("%d%d", &A, &B);add(S, i, A); add(i, S, 0);add(i, T, B); add(T, i, 0);}int u, v, w;for(int i = 1; i <= m; i++) {scanf("%d%d%d", &u, &v, &w);add(u, v, w); add(v, u, w);}int ret = Dinic();printf("%d\n", ret);return 0;}
- POJ 3469 Dual Core CPU //最小割
- POJ 3469 Dual Core CPU(最小割)
- poj 3469 Dual Core CPU 最小割
- 【POJ 3469】 Dual Core CPU --最小割
- POJ 3469 Dual Core CPU | 最小割
- POJ 3469 Dual Core CPU 最小割
- 【最小割】POJ-3469 Dual Core CPU
- poj 3469 Dual Core CPU 最小割
- POJ 3469 Dual Core CPU 最小割
- POJ 3469 --Dual Core CPU【最小割】
- POJ 3469 Dual Core CPU(最小割)
- poj 3469 Dual Core CPU(最小割)
- POJ 3469 Dual Core CPU(最小割)
- poj 3469 Dual Core CPU (最小割模型)
- poj 3469 Dual Core CPU (最小割->最大流)
- poj 3469 Dual Core CPU(最小割)
- POJ 3469 Dual Core CPU 最小割入门题
- POJ 3469 Dual Core CPU(最小割)
- Python内建函数(H)
- hdu 5036 Explosion 2014 ACM/ICPC Asia Regional Beijing Online
- 学习笔记:boost spsc队列
- iOS 的Viewcontroller只支持一个屏幕方向,弹出不同方向,旋转
- im大型分布式实时计费服务器系统架构2.0
- 【最小割】POJ-3469 Dual Core CPU
- BI实施过程中的工具与服务
- winform窗体逻辑
- Sudoku Solver
- 可执行文件ELF的理解
- Leetcode_num9_Binary Tree Inorder Traversal
- Ruby学习笔记-循环与选择结构
- Linux 下安装软件包的方法
- POJ 2871 A Simple Question of Chemistry(水题)