HDU 4289 Control (min. cut)

Source: Internet
Author: User

ControlTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2139 Accepted Submission (s): 904


Problem Description you, the head of Department of Security, recently received a top-secret information that a group of T Errorists is planning to transport some WMD1 from one city to another one (the destination). You know their date, source and destination, and they is using the highway network.
The highway network consists of bidirectional highways, connecting and distinct city. A vehicle can only enter/exit the highway network at cities.
Locate some SA (special agents) in some selected cities, so, then the terrorists enter a city under Observatio N (that is, SA was in this city), they would be caught immediately.
It is possible-locate SA in all cities, but since controlling a city with SA could cost your department a certain amount of money, which might vary from city to city, and your budget might not being able to bear the full cost of controlling all C Ities, you must identify a set of cities, which:
* All traffic of the terrorists must pass at least one city of the set.
* Sum of cost of controlling all cities in the set is minimal.
You could assume that it's always possible-get from source of the terrorists to their destination.
------------------------------------------------------------
1 Weapon of Mass destruction
Input There is several test cases.
The first line of a single test case contains-N and M (2 <= n <=; 1 <= M <= 20000), the Numbe R of cities and the number of highways. Cities is numbered from 1 to N.
The second line contains the S,d (1 <= s,d <= N), the number of the source and the number of the Destinatio N.
The following N lines contains costs. Of these lines the ith one contains exactly one integer, the cost of locating SA in the ith city to put it under Observati On. May assume, the cost are positive and not exceeding 107.
The FOLLOWINGM lines tells you about highway network. Each of these lines contains, integers a and B, indicating a bidirectional highway between A and B.
Please process until EOF (End of File).

Output for all test case should output exactly one line, containing one integer, the sum of the cost of your selected SE T.
See samples for detailed information.
Sample Input
5 65 35234121 55 42 32 44 32 1

Sample Output
3

Source2012 ACM/ICPC Asia Regional Chengdu Online test instructions: Give an infographic, some outlaws to the VS point VT Point, now to seize all the outlaws to prevent them from going to VT, then control some cities to wait for them, The cost of controlling each city is different, and the minimum cost is how much. Solve the problem: the smallest cut, cut all the channels, the cost so that the least, so you can catch all the criminals. Split, each point is split into a forward edge v->v ' edge to control the cost of the city, the original side u->v, then built: u+n->v,v+n->u, edge rights are INF. Then run the maximum flow, that is ans.
/* Max stream: SAP algorithm, the difference from ISAP is no preprocessing */#include <stdio.h> #include <string.h> #include <queue> #include <   algorithm>using namespace std; #define Captype intconst int maxn = 100010;    Total number of points const int MAXM = 400010;    Total number of edges const int INF = 1<<30;struct edg{int to,next; Captype Cap,flow;}  Edg[maxm];int Eid,head[maxn];int GAP[MAXN];  The number of points for each distance (or can be considered a height) int DIS[MAXN];  The shortest distance from each point to the end Enode int CUR[MAXN];    Cur[u] indicates that from the U point can flow through the cur[u] number side int pre[maxn];void init () {eid=0; memset (head,-1,sizeof (Head));}    There are three parameters to the edge, 4 parameters void addedg (int u,int v,captype c,captype rc=0) without a forward edge {edg[eid].to=v; edg[eid].next=head[u]; Edg[eid].cap=c; edg[eid].flow=0;    head[u]=eid++; Edg[eid].to=u;    EDG[EID].NEXT=HEAD[V]; EDG[EID].CAP=RC; edg[eid].flow=0; head[v]=eid++;}    Captype maxflow_sap (int snode,int enode, int n) {//n is the total number of points including the source and sink points, this must be noted memset (Gap,0,sizeof (GAP));    memset (dis,0,sizeof (dis));    memcpy (cur,head,sizeof (head));    Pre[snode] =-1;    Gap[0]=n;  Captype ans=0;    Maximum Flowint U=snode;            while (dis[snode]<n) {//determines from SNode point there is no flow to the next adjacent point if (u==enode) {//Find a way to add flow captype min=inf;            int inser;                for (int i=pre[u]; i!=-1; i=pre[edg[i^1].to])//To find the maximum amount of traffic Min if (min>edg[i].cap-edg[i].flow) {                Min=edg[i].cap-edg[i].flow;            Inser=i;                } for (int i=pre[u]; i!=-1; i=pre[edg[i^1].to]) {edg[i].flow+=min;  Edg[i^1].flow-=min;            Flow of the side that can be recycled} ans+=min;            u=edg[inser^1].to;        Continue  } bool flag = FALSE;        It is possible to determine whether an int v can flow toward the neighboring point from the U point;            for (int i=cur[u]; i!=-1; i=edg[i].next) {v=edg[i].to;                if (edg[i].cap-edg[i].flow>0 && dis[u]==dis[v]+1) {flag=true;                Cur[u]=pre[v]=i;            Break            }} if (flag) {u=v;        Continue }//If a flow adjacent point is not found above, change the distance from the starting point U (can also be consideredis height) the minimum distance of +1 int mind= n for the adjacent flow point;            for (int i=head[u]; i!=-1; i=edg[i].next) if (edg[i].cap-edg[i].flow>0 && mind>dis[edg[i].to]) {            MIND=DIS[EDG[I].TO];        Cur[u]=i;        } gap[dis[u]]--;  if (gap[dis[u]]==0) return ans; When Dis[u] The point of this distance is gone, it is impossible to find an augmented stream path from the source point//Because there is only one distance from the sink point to the current point, then from the source point to the sink point must pass the current point, but the current point is not able to find        Can flow to the point, then the inevitable flow of dis[u]=mind+1;//if a stream of adjacent points is found, the distance is the distance of the adjacent point +1, if not found, then the n+1 gap[dis[u]]++;  if (U!=snode) u=edg[pre[u]^1].to; Return an Edge} return ans;    int main () {int n,m,vs,vt,u,v,cost,ans;        while (scanf ("%d%d", &n,&m) >0) {scanf ("%d%d", &AMP;VS,&AMP;VT);        Vt+=n;        Init ();            for (int i=1; i<=n; i++) {scanf ("%d", &cost);        ADDEDG (i, i+n, cost);            } while (m--) {scanf ("%d%d", &u,&v);            ADDEDG (U+n, V, INF);        ADDEDG (V+n, U, INF); } ANS=MAXFLOW_SAP (vs , VT, n*2);    printf ("%d\n", ans); }}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 4289 Control (min. cut)

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.