多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > 互聯網 > POJ 3469 Dual Core CPU

POJ 3469 Dual Core CPU

來源:程序員人生   發布時間:2014-10-02 08:00:01 閱讀次數:2564次

一堆任務分配到2個不同的芯片上運行,一個任務在不同芯片上運行的時間不一樣,有一些任務組如果分配到不同的芯片上運行會產生額外的時間....

用最小的費用將不同對象劃分到兩個集合 , 最小割問題 .  

建圖:

用源點匯點代表兩個芯片

對某個任務 , 在 A 芯片上運行時間 t1 . 則從源點連一條 到 這個任務容量為 t1 的邊 . 對 B 芯片上運行時間同理

如果兩個任務間有聯系,著再倆個任務間連邊.

原問題就轉化成了, 將圖分成兩部分,所切割的容量最少.

最小割==最大流 isap 解決


Dual Core CPU
Time Limit: 15000MS   Memory Limit: 131072K
Total Submissions: 19127   Accepted: 8263
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

POJ Monthly--2007.11.25, Zhou Dong

[Submit]   [Go Back]   [Status]   [Discuss]




#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn=20200; const int maxm=600300; const int INF=0x3f3f3f3f; struct Edge { int to,next,cap,flow; }edge[maxm]; int Size,Adj[maxn]; int gap[maxn],dep[maxn],pre[maxn],cur[maxn]; void init() { Size=0; memset(Adj,-1,sizeof(Adj)); } void addedge(int u,int v,int w,int rw=0) { edge[Size].to=v; edge[Size].cap=w; edge[Size].next=Adj[u]; edge[Size].flow=0; Adj[u]=Size++; edge[Size].to=u; edge[Size].cap=rw; edge[Size].next=Adj[v]; edge[Size].flow=0; Adj[v]=Size++; } int sap(int start,int end,int N) { memset(gap,0,sizeof(gap)); memset(dep,0,sizeof(dep)); memcpy(cur,Adj,sizeof(Adj)); int u=start; pre[u]=-1;gap[0]=N; int ans=0; while(dep[start]<N) { if(u==end) { int Min=INF; for(int i=pre[u];~i;i=pre[edge[i^1].to]) if(Min>edge[i].cap-edge[i].flow) Min=edge[i].cap-edge[i].flow; for(int i=pre[u];~i;i=pre[edge[i^1].to]) { edge[i].flow+=Min; edge[i^1].flow-=Min; } u=start; ans+=Min; continue; } bool flag=false; int v; for(int i=cur[u];~i;i=edge[i].next) { v=edge[i].to; if(edge[i].cap-edge[i].flow&&dep[v]+1==dep[u]) { flag=true; cur[u]=pre[v]=i; break; } } if(flag) { u=v; continue; } int Min=N; for(int i=Adj[u];~i;i=edge[i].next) { if(edge[i].cap-edge[i].flow&&dep[edge[i].to]<Min) { Min=dep[edge[i].to]; cur[u]=i; } } gap[dep[u]]--; if(!gap[dep[u]]) return ans; dep[u]=Min+1; gap[dep[u]]++; if(u!=start) u=edge[pre[u]^1].to; } return ans; } int n,m; int main() { while(scanf("%d%d",&n,&m)!=EOF) { init(); for(int i=1;i<=n;i++) { int a,b; scanf("%d%d",&a,&b); addedge(0,i,a); addedge(i,n+1,b); } for(int i=0;i<m;i++) { int u,v,w; scanf("%d%d%d",&u,&v,&w); addedge(u,v,w,w); } printf("%d ",sap(0,n+1,n+2)); } return 0; }



生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 国产一区二区三区精品久久呦 | 日韩手机视频 | 国产福利自产拍在线观看 | 欧美精品v国产精品v日韩精品 | 免费视频在线观看网站 | 日本国产亚洲 | 成人永久福利在线观看不卡 | 宇都宫紫苑野外中文字幕 | 亚洲自拍图片区 | 亚洲欧美精品 | 性欧美精品久久久久久久 | 成人在色线视频在线观看免费大全 | 亚洲欧美一二三区 | 久久一本一区二区三区 | 欧美非洲黑人性xxxx | 国产精品乱码一区二区三区 | 亚洲v日本v欧美v综合v | 999av视频| 国产在线精品福利一区二区三区 | 国产三级在线观看视频 | 久久久福利 | 欧美精品亚洲精品日韩一区 | 亚洲精品国产精品乱码不97 | 最新日本一级中文字幕 | 精品一区二区三区在线观看 | 在线免费观看国产视频 | 国内精品久久久久久不卡影院 | 国产一区二区色淫影院 | 亚洲人成网站在线观看播放青青 | 亚洲成人黄色网址 | 日韩在线一区二区 | 欧美成人精品高清在线观看 | 国产精品久久久久影院色老大 | 成人精品亚洲人成在线 | 真人肉体一级毛片 | h小视频在线 | 91精品国产欧美一区二区 | 久久无码精品一区二区三区 | 激情中文字幕 | 性欧美videos | 伊人久久成人爱综合网 |