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.
Edge Point, point right for profit
Establish maximum closed sub-graph, run maximum flow
Yield = Total revenue-Maximum flow
1#include <cstdio>2#include <cmath>3#include <cstring>4#include <iostream>5 using namespacestd;6 Const intn=50100, m=50010, inf=100000000;7 structee{intTo,next,f;} e[(m+n) *Ten];8 inthead[n+m],dis[n+m],q[n+M];9 intAns,n,m,s,t,cnt=1;Ten voidInsintUintVintf) { Onee[++cnt].to=v,e[cnt].next=head[u],e[cnt].f=f,head[u]=CNT; Ae[++cnt].to=u;e[cnt].next=head[v];e[cnt].f=0, head[v]=CNT; - } - BOOLBFs () { the for(intI=1; i<=t;i++) dis[i]=inf; - intH=0, t=1, now; -q[1]=s;dis[s]=0; - while(h!=t) { +now=q[++h]; - for(intI=head[now];i;i=E[i].next) { + intv=e[i].to; A if(e[i].f&&dis[now]+1<Dis[v]) { atdis[v]=dis[now]+1; - if(v==t)return 1; -q[++t]=v; - } - } - } in if(Dis[t]==inf)return 0;return 1; - } to + intDinic (intNowintf) { - if(now==t)returnF; the intrest=F; * for(intI=head[now];i&&rest;i=E[i].next) { $ intv=e[i].to;Panax Notoginseng if(dis[v]==dis[now]+1&&e[i].f) { - intt=dinic (V,min (REST,E[I].F)); the if(t==0) dis[v]=0; +rest-=T; Ae[i].f-=T; thee[i^1].f+=T; + } - } $ returnF-rest; $ } - - intMain () { thescanf"%d%d",&n,&m); -s=0, t=n+m+1;Wuyi intx,u,v; the for(intI=1; i<=n;i++){ -scanf"%d",&x); Wu ins (s,i,x); - } About for(intI=1; i<=m;i++){ $scanf"%d%d%d",&u,&v,&x); -INS (i+n,t,x); -ans+=x; -INS (u,i+n,inf); AINS (v,i+n,inf); + } the while(BFS ()) -ans-=dinic (s,inf); $printf"%d", ans); the}
"Bzoj 1497" [NOI2006] Maximum profit