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

國內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > 互聯(lián)網(wǎng) > POJ 3469(Dual Core CPU-最小割)[Template:網(wǎng)絡(luò)流dinic V2]

POJ 3469(Dual Core CPU-最小割)[Template:網(wǎng)絡(luò)流dinic V2]

來源:程序員人生   發(fā)布時(shí)間:2014-11-03 08:47:38 閱讀次數(shù):3043次

Language:
Dual Core CPU
Time Limit: 15000MS   Memory Limit: 131072K
Total Submissions: 19321   Accepted: 8372
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-⑵007.11.25, Zhou Dong


最小割的模板,其實(shí)就是最大流

注意:

Verson 2:

1.修復(fù)Bug,在本次模板中修改了q隊(duì)列的長度,


題目,裸最小割,

設(shè)S為用模塊A的集合,T為模塊B

s->任務(wù)i  //模塊B的cost

任務(wù)i->t  //模塊A的cost

任務(wù)i->任務(wù)j //(i,j)不在1個(gè)集合的cost,注意最小割,要2個(gè)方向(最小割只保證s->t沒路徑,t->s的路徑不用割)







#include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<functional> #include<iostream> #include<cmath> #include<cctype> #include<ctime> using namespace std; #define For(i,n) for(int i=1;i<=n;i++) #define Fork(i,k,n) for(int i=k;i<=n;i++) #define Rep(i,n) for(int i=0;i<n;i++) #define ForD(i,n) for(int i=n;i;i--) #define RepD(i,n) for(int i=n;i>=0;i--) #define Forp(x) for(int p=pre[x];p;p=next[p]) #define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (x<<1) #define Rson ((x<<1)+1) #define MEM(a) memset(a,0,sizeof(a)); #define MEMI(a) memset(a,127,sizeof(a)); #define MEMi(a) memset(a,128,sizeof(a)); #define INF (2139062143) #define F (100000007) #define MAXn (20000+10) #define MAXm (200000+10) #define MAXN (MAXn+2) #define MAXM ((MAXn*2+MAXm*2)*2+100) long long mul(long long a,long long b){return (a*b)%F;} long long add(long long a,long long b){return (a+b)%F;} long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;} typedef long long ll; class Max_flow //dinic+當(dāng)前弧優(yōu)化 { public: int n,s,t; int q[MAXN]; int edge[MAXM],next[MAXM],pre[MAXN],weight[MAXM],size; void addedge(int u,int v,int w) { edge[++size]=v; weight[size]=w; next[size]=pre[u]; pre[u]=size; } void addedge2(int u,int v,int w){addedge(u,v,w),addedge(v,u,0);} bool b[MAXN]; int d[MAXN]; bool SPFA(int s,int t) { For(i,n) d[i]=INF; MEM(b) d[q[1]=s]=0;b[s]=1; int head=1,tail=1; while (head<=tail) { int now=q[head++]; Forp(now) { int &v=edge[p]; if (weight[p]&&!b[v]) { d[v]=d[now]+1; b[v]=1,q[++tail]=v; } } } return b[t]; } int iter[MAXN]; int dfs(int x,int f) { if (x==t) return f; Forpiter(x) { int v=edge[p]; if (weight[p]&&d[x]<d[v]) { int nowflow=dfs(v,min(weight[p],f)); if (nowflow) { weight[p]-=nowflow; weight[p^1]+=nowflow; return nowflow; } } } return 0; } int max_flow(int s,int t) { int flow=0; while(SPFA(s,t)) { For(i,n) iter[i]=pre[i]; int f; while (f=dfs(s,INF)) flow+=f; } return flow; } void mem(int n,int s,int t) { (*this).n=n; (*this).t=t; (*this).s=s; size=1; MEM(pre) } }S; int n,m; int main() { // freopen("poj3469.in","r",stdin); // freopen(".out","w",stdout); scanf("%d%d",&n,&m); int s=1,t=n+2; S.mem(n+2,s,t); For(i,n) { int ai,bi; scanf("%d%d",&ai,&bi); S.addedge2(i+1,t,ai); S.addedge2(s,i+1,bi); } For(i,m) { int a,b,w; scanf("%d%d%d",&a,&b,&w); S.addedge(a+1,b+1,w); S.addedge(b+1,a+1,w); } cout<<S.max_flow(s,t)<<endl; return 0; }





生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 国产区精品福利在线观看精品 | 亚洲日韩中文字幕一区 | 午夜欧美精品久久久久久久久 | 亚洲天堂中文字幕在线观看 | 亚洲国产精品综合一区在线 | 日韩精品视频在线播放 | 国产精品老女人精品视 | 成人免费视频在线播放 | 综合网小说图片区 | 中文亚洲欧美 | 国产免费高清福利拍拍拍 | 另类专区亚洲 | 伊人高清视频 | 最近中文字幕在线视频 | 玖玖五月 | 高清在线精品一区二区 | 成年人视频免费在线观看 | 最新欧美精品一区二区三区 | 最猛黑人xxxⅹ黑人猛交 | japanxxxx日本黑人 | 国产一区亚洲欧美成人 | 最新中文 | 欧美国产日本 | 色噜噜影院 | 欧美亚洲精品在线 | nnnwww在线观看视频 | 久久精品免费看 | www.看片| 亚洲精品久久久久网站 | 免费播放欧美毛片欧美a | 欧美性受一区二区三区 | 日本叼嘿视频 | 欧美亚洲另类图片 | 日韩亚洲欧美性感视频影片免费看 | 羞羞网站在线观看 | 日本动漫片b站免费观看 | 午夜影院h | 爱爱永久免费视频网站 | 69av免费观看 | 欧美亚洲激情视频 | 亚洲欧美另类日本 |