BZOJ3280: Little R's Trouble

Source: Internet
Author: User

Exercises

Just build a fee flow can be past it ...

Code:

1#include <cstdio>2#include <cstdlib>3#include <cmath>4#include <cstring>5#include <algorithm>6#include <iostream>7#include <vector>8#include <map>9#include <Set>Ten#include <queue> One#include <string> A #defineINF 1000000000 - #defineMAXN 100000+5 - #defineMAXM 100000+5 the #defineEPS 1e-10 - #definell Long Long - #definePA pair<int,int> - #defineFor0 (i,n) for (int i=0;i<= (n); i++) + #defineFor1 (i,n) for (int i=1;i<= (n); i++) - #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) + #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) A #defineFor4 (i,x) for (int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go) at #defineMoD 1000000007 - using namespacestd; -InlineintRead () - { -     intx=0, f=1;CharCh=GetChar (); -      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} in      while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} -     returnx*F; to } + intn,m,k,mincost,maxflow,tot=1, S,SS,T,SUM,A[MAXN],HEAD[MAXN],D[MAXN], from[2*MAXM]; - BOOLV[MAXN]; thequeue<int>Q; * structedge{int  from, Go,next,v,c;} e[2*MAXM]; $ voidAddintXintYintZintW)Panax Notoginseng { -E[++tot]= (Edge) {x,y,head[x],z,w};head[x]=tot; theE[++tot]= (Edge) {Y,x,head[y],0,-w};head[y]=tot; + } A BOOLSPFA () the { +      for(inti=s;i<=t;i++) {v[i]=0;d [i]=inf;} -Q.push (s);d [s]=0; v[s]=1; $      while(!q.empty ()) $     { -         intX=q.front (); Q.pop (); v[x]=0; -          for(intI=head[x],y;i;i=e[i].next) the          if(e[i].v&&d[x]+e[i].c<d[y=E[i].go]) -          {WuyiD[Y]=D[X]+E[I].C; from[y]=i; the             if(!v[y]) {v[y]=1; Q.push (y);} -          } Wu     } -     returnd[t]!=inf; About } $ voidMCF () - { -mincost=0; maxflow=0; -      while(SPFA ()) A     { +         inttmp=inf; the          for(intI= from[t];i;i= from[E[i]. from]) tmp=min (tmp,e[i].v); -mincost+=d[t]*tmp;maxflow+=tmp; $          for(intI= from[t];i;i= from[E[i]. from]) {e[i].v-=tmp;e[i^1].v+=tmp;} the     } the } the intMain () the { -Freopen ("Input.txt","R", stdin); inFreopen ("output.txt","W", stdout); the     intT=read (), cs=0; the      while(t--) About     { theN=read (); M=read (); K=read (); sum=0; thes=0; ss=2*n+1; t=ss+1; theMemset (Head,0,sizeof(head)); tot=1; + For1 (i,n) -         { theA[i]=read (); sum+=A[i];BayiAdd (S,i,a[i],0); theAdd (I+n,t,a[i],0); the         } -For1 (i,n-1) Add (i,i+1Inf0); - For1 (i,m) the         { the             intX=read (), y=read (); the Add (s,ss,x,y); the         } -For1 (i,n) Add (Ss,i+n,inf,0); the For1 (i,k) the         { the             intX=read (), y=read ();94For1 (j,n-x-1) Add (j,j+x+1+n,inf,y); the         } the MCF (); theprintf"Case %d:",++CS);98         if(maxflow!=sum) printf ("impossible\n");Elseprintf"%d\n", mincost); About     } -                 101     return 0;102}
View Code 3280: Little R's Trouble time limit:10 Sec Memory limit:512 MB
submit:138 solved:62
[Submit] [Status] Description Small R recently encountered a big trouble, his program design Hang branch. So he had to find Cheng teacher plead. The good Cheng teacher promised not to hang him, but asked Little R to help him solve a difficult problem together. The problem is that Cheng recently had to conduct an evil experiment to prove P=NP, the experiment lasted n days, the first day I need A[i] a graduate student to bring him bricks. After all, graduate students are also people, so the use of graduate students need money, witty Cheng teacher has contacted M University, J University of L[j] a graduate student, while hiring a graduate student in this university need p[j] yuan money. Originally Cheng teacher filled with joy thought, so pick the cheapest max{a[i]} A graduate student hired, you can complete the experiment; The result did not expect, because he asked graduate students to work 25 hours a day not to eat to sleep in the toilet drink water talk cough sneeze breathing air, So all the graduate students who came down to his brick one day would go to near-death status. There is no doubt that a graduate student of near-death status can no longer work. But the witty teacher early contact with the K Home Hospital, the first hospital to heal a dying graduate students need d[i] days, and need q[i] yuan money.

Now, Cheng the teacher wants to know, at least how much money, can be in this n days to meet the daily needs? If this is not possible, please output "impossible". Note that because Cheng teacher's conscience is so bad, he can not send the dying graduate student to the hospital!

Input

The subject contains multiple sets of data; The first line is a number T (t<=11), which represents the number of data groups and the following T-group data.
For each set of data, the first row of three numbers, n,m,k;
The following row n number, representing A[1]...a[n]
Then a line of 2m number, indicating l[1],p[1]...l[n],p[n]
Then a line of 2k number, indicating d[1],q[1]...d[n],q[n]

Output

For each set of data, output a row in a sample format, with two numbers representing the first group of data and the minimum amount of money.

Sample Input2
3 2 1
10 20 30
40 90 15 100
1 5
3 2 1
10 20 30
40 90 15 100
2 5
Sample OutputCase 1:4,650
Case 2:impossible
HINT

Example explanation: Buy 90 dollars of the 40 graduate students, and then buy 10 100 yuan. In this way, the first day of the use of 10 people to the hospital, then they can continue to use the third day, and the next day and the third day with the new graduate students to make up, so altogether need to spend 40*90 + 10*100 + 5*10 = 4650 yuan.

Data size:

For each set of data in 30% of the data,

Satisfies the n<=5,m,k<=2, the remaining number is less than or equal to 100 or

n<=10,m,k<=10, the remaining numbers are less than or equal to 20.

For 100% of data

N,m,k<=50, the remaining numbers are less than or equal to 100.

Source

Network flow

BZOJ3280: Little R's Trouble

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.