Exercises
This seems to be a long time ago a pit?
The edge has a lower bound, the source has a sink, the source to 1 connected edge, each point can be connected to the edge.
Then add the lower bound and the cost to the edge of the point to find the minimum feasible cost flow.
But!!! T!!! Since each augmentation can only be +1 capacity, augmented 5000+ times ... t_t
Once again planted on the cost stream! After learning zkw again come back a This problem.
Dig Pit to fill ...
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 1000 - #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,tot=1, S,T,SS,TT,HEAD[MAXN],D[MAXN], from[2*MAXM]; - BOOLV[MAXN]; thequeue<int>Q; * structedge{int from, Go,next,v,c;} e[2*MAXM]; $ voidAddintXintYintVintc)Panax Notoginseng { -E[++tot]= (Edge) {x,y,head[x],v,c};head[x]=tot; theE[++tot]= (Edge) {Y,x,head[y],0,-c};head[y]=tot; + } AInlinevoidInsertintXintYintLintRintc) the { + if(l) {Add (ss,y,l,c); Add (X,tt,l,0);} -Add (x,y,r-l,c); $ } $ BOOLSPFA () - { - for(intI=0; i<=t;i++) {v[i]=0;d [i]=inf;} theQ.push (s);d [s]=0; v[s]=1; - while(!q.empty ())Wuyi { the intX=q.front (); Q.pop (); v[x]=0; - for(intI=head[x],y;i;i=e[i].next) Wu if(e[i].v&&d[x]+e[i].c<d[y=E[i].go]) - { AboutD[Y]=D[X]+E[I].C; from[y]=i; $ if(!v[y]) {v[y]=1; Q.push (y);} - } - } - returnd[t]!=inf; A } + voidMCF () the { -mincost=0; $ while(SPFA ()) the { the inttmp=inf; the for(intI= from[t];i;i= from[E[i]. from]) tmp=min (tmp,e[i].v); themincost+=d[t]*tmp; - for(intI= from[t];i;i= from[E[i]. from]) {e[i].v-=tmp;e[i^1].v+=tmp;} in } the } the intMain () About { theFreopen ("Input.txt","R", stdin); theFreopen ("output.txt","W", stdout); then=read (); +s=0; t=n+1; ss=t+1; tt=t+2; -Insert (S,1,0Inf0); the For1 (i,n)Bayi { the inttmp=read (); the For1 (j,tmp) - { - intX=read (), y=read (); theInsert (I,x,1, inf,y); the } theInsert (I,t,0Inf0); the } -Insert (T,s,0Inf0); thes=ss;t=tt; the MCF (); theprintf"%d\n", mincost);94 return 0; the}View Code 3876: [Ahoi2014] Spur plot time limit:10 Sec Memory limit:256 MB
Submit:4 solved:1
[Submit] [Status] Description "Story Background" otaku jyy very much like to play RPG games, such as Paladin, Xuan Jian and so on. But jyy like not fighting scenes, but similar to the drama of the general hatred of the story. These games tend to have a lot of spur plots, and now jyy want to spend the least time watching all the spur plots. "Problem description" Jyy now play in the RPG game, there are a total of n plot points, from 1 to n numbered, the first I plot points can be based on the different choices of jyy, and through different spur plot, go to the different new plot point ki. Of course, if it is 0, it means that the I plot point is a game ending. Jyy It takes some time to watch a spur plot. Jyy began at the 1th plot point, the beginning of the game. Obviously any plot point is from the number 1th plot point can reach. In addition, as the game progresses, the plot is irreversible. So the game is guaranteed to start from any plot point, can not return to this plot point. Because jyy overuse modifier, resulting in the game's "archive" and "read" function damage, so jyy to go back to the previous plot point, the only way is to exit the current game, and start a new game, that is, back to the 1th plot point. Jyy can exit the game at any time and start over again. Constantly start a new game repeatedly watching the plot has been seen is very painful, jyy hope to spend the least time, read all the different spur plot. Input line contains a positive integer n. Next n lines, I act the information of the plot point of I; the first integer is, the next integer pair, bij and Tij, represents the time from the plot point I can go to the plot point and watch the line plot take. Output
The output line contains an integer that represents the minimum time required for jyy to read all the spur plots.
Sample Input6
2 2 1) 3 2
2 4 3) 5 4
2 5 5) 6 6
0
0
0Sample Output -HINT
Jyy need to start the Game 3 times, plus a first game, 4 times the game process is
1->2->4,1->2->5,1->3->5 and 1->3->6.
For 100% of data meet N<=300,0<=ki<=50,1<=tij<=300,sigma (Ki) <=5000
Source
by anonymous upload
BZOJ3876: [Ahoi2014] Spur plot