BZOJ1497 [NOI2006] Maximum profit

Source: Internet
Author: User

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.

Positive solution: maximum flow, minimum cut

Problem Solving Report:

Linear programming and network flow 24 question of the second question, because today's test withered, so I opened the pit angrily, set the flag to brush the network flow 24 questions.

The model of this problem is exactly the same as the T2, which is the maximum right-closing sub-graph. Top:

Considering what test instructions gives us is a map with a point of view, and asks us to ask for the maximum right of the graph to close the sub-graph, to get the scheme and the maximum weight. The definition of a closed sub-graph is that the out point of all the edges of a closed sub-figure v that has s is also a v.

That is, if we choose a point then its out point can all and must be selected into the graph, we need to maximize the point in the graph and.

At first glance I feel like a DP s inf t Even a volume is the absolute value of the point right of the edge.

Because we want to maximize the point in the graph and, obviously, we expect to pick as many positive points as possible, but every time we choose a positive point we have to pick some other negative points of positive point connection. At the same time, if we are to choose the right point of the negative power to bring more negative, obviously we can not choose this right point. may wish to set tot for all the right points of the point and we want to get a maximum value Span style= "FONT-FAMILY:CALIBRI;" >ans - absolute sum of negative weights. So ans=tot- No right to select and + ans=tot-( Span style= "font-family: the song Body;" > do not select the positive and - negative right absolute value and )

Consider the feasibility of establishing a model. If we run the minimum cut for this well-built chart, we can get to the side of the S and the side near T. It is easy to think of all the points near the side of S that are all we need to pick. If the out edge of S is full-flow, that is, the edge of the smallest cut, then the choice of the positive point is not conducive to the total answer, because he can not make his connected side full flow, so because this edge is in the smallest cut, then this right point is near T on one side, cannot choose. Conversely, if A line of T is full of flow, stating that the right of his point of power is sufficient to exceed the absolute value of all the points of the constraint, then the positive point and all points connected to him are divided into the final scheme to be selected.

This is the feasibility of the algorithm. Obviously, the minimum cut is equal to the maximum flow, so we just have to run through the dinic on the graph .

Scenario, the DFS can arrive at a Point in the set that is connected to S.

  

1 //It's made by jump~2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <algorithm>8#include <ctime>9#include <vector>Ten#include <queue> One#include <map> A#include <Set> - #ifdef WIN32 - #defineOT "%i64d" the #else - #defineOT "%lld" - #endif - using namespacestd; +typedefLong LongLL; - Const intMAXN =55011; + Const intMAXM =500011; A Const intINF = (1<< in); at intn,m,s,t; - intFIRST[MAXN],ECNT,DEEP[MAXN]; - intAns,tot; -queue<int>Q; - structedge{ -     intto,next,f; in }E[MAXM]; -  toInlineintGetint () + { -        intw=0, q=0; the        CharC=GetChar (); *         while((c<'0'|| C>'9') && c!='-') c=GetChar (); $        if(c=='-') q=1, c=GetChar ();Panax Notoginseng         while(c>='0'&& c<='9') w=w*Ten+c-'0', c=GetChar (); -        returnQ? -w:w; the } +  AInlinevoidLinkintXintYintz) { theE[++ECNT].NEXT=FIRST[X]; first[x]=ecnt; E[ecnt].to=y; e[ecnt].f=Z; +E[++ecnt].next=first[y]; first[y]=ecnt; E[ecnt].to=x; e[ecnt].f=0; - } $  $InlineBOOLBFS () { -      while(!Q.empty ()) Q.pop (); -      for(intI=1; i<=t;i++) deep[i]=inf; theQ.push (S); deep[s]=1; -      while(!Q.empty ()) {Wuyi     intu=Q.front (); Q.pop (); the      for(intI=first[u];i;i=E[i].next) { -         if(E[i].f && deep[e[i].to]==inf) { WuQ.push (e[i].to); deep[e[i].to]=deep[u]+1; -         } About     } $     } -     if(Deep[t]==inf)return false; -     return true; - } A  +InlineintMaxflow (intXintremain) { the     if(X==t | | remain==0)returnremain;//Pruning -     intflow=0, F; $      for(intI=first[x];i;i=E[i].next) { the     if(E[i].f && deep[e[i].to]==deep[x]+1) { the         intv=e[i].to; f=Maxflow (V,min (REMAIN,E[I].F)); the         if(f) { theFlow+=f; E[i].f-=f; e[i^1].f+=F; -remain-=F; in         if(remain==0)returnflow; the         } the         Elsedeep[v]=-1; About     } the     } the     returnflow; the } +  -InlinevoidWork () { theN=getint (); M=getint (); Ecnt=1;Bayis=m+n+1; t=s+1;intx; the      for(intI=1; i<=n;i++) x=getint (), Link (i,t,x); the      for(intI=1; i<=m;i++) { -X=getint (); Link (i+n,x,inf); -X=getint (); Link (i+n,x,inf); theX=getint (); Tot+=x; Link (s,i+n,x);  the     }        the      while(BFS ()) {ans+=Maxflow (S,inf);} theprintf"%d", tot-ans); - } the  the intMain () the {94 Work (); the   return 0; the}

BZOJ1497 [NOI2006] Maximum profit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.