Time Limit:5 Sec Memory limit:64 MB
submit:4449 solved:2181 Description
The new technology is hitting the mobile phone market, for the major operators, this is both an opportunity, but also a challenge. Thu Group's Cs&t Communications company in the new generation of communications technology on the eve of a bloody battle, need to do too much preparation, only to choose one site, you need to complete the preliminary market research, site survey, optimization and other projects. After the preliminary market survey and site survey, the company got a total of n can be used as a communication signal transfer station address, and due to the geographical differences of these addresses, the construction of communication stations in different places need to invest in the cost is not the same, Fortunately, after a preliminary investigation, these are known data: The cost of establishing the I Communication Hub is pi (1≤i≤n). In addition the company survey has drawn all the expected user groups, altogether m. Information about the I user base is summarized as AI, Bi, and CI: These users use broker AI and broker bi for communication, and the company can benefit from CI. (1≤i≤m, 1≤ai, Bi≤n) the cs&t Company of Thu Group can choose to set up a number of transit stations (input costs), provide services to some users and gain benefits. So how to choose the final station to make the company's net profit maximum? (Net Profit = sum of benefits-sum of input costs)
Input
The first line in the input file has two positive integers n and M. In the second row, there are n integers that describe the cost of establishing each communication station, in turn P1, P2, ..., PN. The following M-line, the three-digit AI, bi, and CI of the line (i + 2) describe the information for the I-user group. The meaning of all variables can be found in the topic description.
Output
Your program simply outputs an integer to the output file, indicating the maximum net profit a company can get.
Sample Input5 5
1 2 3) 4 5
1 2 3
2 3 4
1 3 3
1 4 2
4 5 3
Sample Output4
HINT
"Sample description" Select the establishment of 1, 2, 3rd, the transfer station, the cost of investment 6, profit is 10, so the maximum gain of 4. "Scoring method" is not part of the subject, your program output only and our answer exactly the same to obtain full marks, otherwise do not score. Data size and convention 80%: N≤200,m≤1 000. 100% of the data: N≤5 000,m≤50 000,0≤ci≤100,0≤pi≤100.
Source
Minimum network flow Cut
Connect to each broker from the source point, the capacity is the construction cost.
Connect to the user group from the broker, the capacity is INF
From the user base to the meeting point edge, the capacity is profitable.
Minimum cut. If the profit is greater than the cost, the minimum cut will cut off the left side of the cost, if the cost is greater than the profit, the minimum cut will cut off the profit margin on the right.
The sum of the profits of all user groups minus the minimum cut is the answer (either pay the cost-building transit, or give up a portion of the profit).
1 /*by Silvern*/2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <queue>8 using namespacestd;9 Const intinf=1e9;Ten Const intmxn=100010; One intRead () { A intx=0, f=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} - while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} the returnx*F; - } - structedge{ - intv,nxt,f; +}e[mxn<<3]; - inthd[mxn],mct=1; + voidAdd_edge (intUintVintc) { AE[++MCT].V=V;E[MCT].F=C;E[MCT].NXT=HD[U];HD[U]=MCT;return; at } - voidInsertintUintVintc) { -Add_edge (u,v,c); Add_edge (V,u,0);return; - } - intn,m,s,t; - intD[MXN]; in BOOLBFS () { -memset (D,0,sizeofd); tod[s]=1; +queue<int>Q; - Q.push (S); the while(!Q.empty ()) { * intu=Q.front (); Q.pop (); $ for(intI=hd[u];i;i=e[i].nxt) {Panax Notoginseng intv=e[i].v; - if(!d[v] &&e[i].f) { thed[v]=d[u]+1; Q.push (v); + } A } the } + returnD[t]; - } $ intDFS (intUintLim) { $ if(u==t)returnLim; - inttmp,f=0; - for(intI=hd[u];i;i=e[i].nxt) { the intv=e[i].v; - if(d[v]==d[u]+1&&e[i].f) {Wuyitmp=DFS (V,min (LIM,E[I].F)); thee[i].f-=tmp; -e[i^1].f+=tmp; Wulim-=tmp; -f+=tmp; About if(!lim)returnF; $ } - } -d[u]=0; - returnF; A } + intDinic () { the intres=0; - while(BFS ()) res+=DFS (s,1e9); $ returnRes; the } the intMain () { theN=read (); m=read (); thes=0; t=n+m+1; - inti,j,w,a,b; in for(i=1; i<=n;i++){ thew=read (); the Insert (s,i,w); About } the intsmm=0; the for(i=1; i<=m;i++){ theA=read (); B=read (); w=read (); +Insert (a,n+i,inf); -Insert (b,n+i,inf); theInsert (n+i,t,w);Bayismm+=W; the } the intans=smm-dinic (); -printf"%d\n", ans); - return 0; the}
Bzoj1497 [NOI2006] Maximum profit