Dual Core CPU
Time Limit: 15000MS |
|
Memory Limit: 131072K |
Total Submissions: 24830 |
|
Accepted: 10756 |
Case Time Limit: 5000MS |
Description
As more and more computers is equipped with dual core CPU, SETAGLILB, the chief technology Officer of Tinysoft Corporatio N, decided to update their famous PRODUCT-SWODNIW.
The routine consists of N modules, and each of the them should run in a certain core. The costs for all the routines-to-execute on both 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 is running on the same core and then the cost of this action can be ignored. Otherwise, some extra cost is needed. You should arrange wisely to minimize.
Input
There is integers in the first line of input data, n and M (1≤ n ≤ 20000, 1≤ m ≤200000).
The next N lines, each contains the integer, Ai and Bi.
In the following M lines, each contains three integers: a, b, W. The meaning is so 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
Source
POJ monthly--2007.11.25, Zhou Dongtitle Link: http://poj.org/problem?id=3469Test Instructions: Each problem on a A, B processor with different costs, there are some problems on different processors to add additional cost, to deal with all problems required by the minimum cost. idea: The problem is linked to a, B, the edge of the cost. Divide them into two sets, with a in the representation of a set on a top handle, with B in the representation of a set on B above, if the cost is minimal, that is the minimum cut. But there are some things that need extra cost to deal with different processors, and that creates the edge right between them, so separating them will increase the cost. The minimum cut problem is the maximum flow. The Benquan value of this problem is large, note if the General augmented path algorithm (i.e. in the residual network, each time to find an augmented path), the time complexity of O (FVE), and the maximum flow, the shortest augmented path algorithm (in the hierarchical network, with the DFS implementation of multiple augmentation, that is, dinic algorithm) time complexity O ( VVE). Code:
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<Set>#include<map>#include<queue>#include<stack>#include<vector>using namespacestd;#definePI ACOs (-1.0)typedefLong LongLl;typedef pair<int,int>P;Const intmaxn=1e5+ -, maxm=1e5+ -, inf=0x3f3f3f3f, mod=1e9+7;Constll inf=1e18+7;p Riority_queue<P,vector<P>,greater<P> >que;structedge{int from, to; intcap; intRev;///number of direction edges};vector<edge>G[maxn];///adjacency Table Store mapintITER[MAXN];///The current arc, on its previous side, has no effect.intLEVEL[MAXN];///levelvoidAddedge (intUintVintc) {Edge E; E. from=u,e.to=v,e.cap=c,e.rev=g[v].size (); G[u].push_back (e); E. from=v,e.to=u,e.cap=0, E.rev=g[u].size ()-1; G[v].push_back (e);}intBFsintSintt) {memset (level,-1,sizeof(level)); Queue<int>Q; Level[s]=0; Q.push (s); while(!Q.empty ()) { intu=Q.front (); Q.pop (); for(intI=0; I<g[u].size (); i++) {Edge e=G[u][i]; if(e.cap>0&&level[e.to]<0) {level[e.to]=level[u]+1; Q.push (e.to); } } } if(level[t]<0)return 0; Else return 1;}intDfsintUintTintf) { if(u==t| | f==0)returnF; intflow=0; for(int&i=iter[u]; I<g[u].size (); i++) {Edge e=G[u][i]; if(e.cap>0&&level[u]+1==Level[e.to]) { intD=Dfs (E.to,t,min (f,e.cap)); if(d>0) {G[u][i].cap-=D; G[e.to][e.rev].cap+=D; Flow+=D; F-=D; if(f==0) Break; } } } returnflow;}intMax_flow (intSintt) { intflow=0; while(BFS (s,t)) {memset (ITER,0,sizeof(ITER)); Flow+=DFS (S,t,inf); } returnflow;}intMain () {intn,m; scanf ("%d%d",&n,&m); ints=0, t=n+1; for(intI=1; i<=n; i++) { intb; scanf ("%d%d",&a,&b); Addedge (S,i,a); Addedge (I,T,B); } for(intI=1; i<=m; i++) { inta,b,w; scanf ("%d%d%d",&a,&b,&W); Addedge (A,B,W); Addedge (B,A,W); } cout<<max_flow (s,t) <<Endl; return 0;}
Maximum Flow template
POJ 3469.Dual Core CPU Max stream dinic algorithm template