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 for 100% of the data to meet N<=300,0<=ki<=50,1<=tij<=300,sigma (Ki) <=5000: This question is a bit like bzoj2324[zjoi2011] to rescue Pikachu, However, this topic requires access to each edge, not to every point. Divide each point I into i1 and i2, increase the edge of the I1-->I2, the capacity is INF, the cost is 0. For the topological node I with the degree x, increase the edge of x i2-->t, the capacity is 1, the cost is corresponding to the Benquan of the edge, indicating that the x edge is to be accessed. For node I with degrees X, increase the edge of 1 s-->i1, the capacity is X, and the cost is 0, indicating that the X-entry is accessed and can be considered to be restarted from that point. For point Pairs (i,j), if I point can reach J Point, then increase the edge of i1-->j2, the capacity is INF, the cost is distance, indicating from I point to go to J Point, so that can access a plot from J Point. Set the starting point to R, add a s-->r1 edge, the capacity is INF, the cost is 0, indicating starting from the starting point. Once this is done, run through the ZKW fee flow. Code:
varo,v:Array[0.. the] ofBoolean; F,s,d,dis:Array[0.. the] ofLongint; Next,p,c,w:Array[-100000..100000] ofLongint; I,j,k,l,y,t,tt,ft,n,ff,st,sf,ans,imp,new,flow:longint; A:Array[0..301,0..301] ofLongint; Tot:Array[0..301] ofLongint;procedurelink (i,j,k,l:longint);beginInc (T); NEXT[T]:=d[i]; d[i]:=t; P[t]:=j; C[t]:=k; w[t]:=l; next[-T]:=D[J]; D[j]:=-t; P[-t]:=i; w[-t]:=-l;End;functionDFS (i,flow:longint): Longint;varJ,k,l,min:longint;begin ifI=tt Then beginInc (Ans,dis[i)*flow); Exit (flow); End; K:=s[i]; J:=P[K]; dfs:=0; O[i]:=true; v[i]:=true; whileK<>0 Do beginL:=DIS[I]+W[K]-DIS[J]; min:=flow; ifC[k]<min Thenmin:=C[k]; if(min>0) and(L<f[j]) Thenf[j]:=M; if(min>0) and(l=0) and( notO[J]) Then beginL:=DFS (j,min); Inc (DFS,L); Dec (flow,l); Dec (c[k],l); Inc (C[-k],l); End; ifflow=0 ThenBreak ; S[i]:=Next[s[i]]; K:=s[i]; j:=P[k]; End; O[i]:=false;End;beginREADLN (n); TT:=2*n+1; fori:=1 toN Do forj:=1 toN DoA[i,j]:=maxlongintDiv 2; fori:=1 toN Do beginread (k); forj:=1 toK Do beginread (l,y); A[I,L]:=y; Inc (Tot[l]); Link (i,2*n+1,1, y); End; End; fork:=1 toN Do fori:=1 toN Do forj:=1 toN Do ifA[I,K]+A[K,J]<A[I,J] Thena[i,j]:=a[i,k]+A[k,j]; fori:=1 toN Do forj:=1 toN Do if(I<>J) and(A[i,j]<maxlongintDiv 2) ThenLink (i+n,j,1Shl -, A[i,j]); Link (0,1+n,1Shl -,0); fori:=1 toN DoLink0, I+n,tot[i],0); fori:=1 toN DoLink (i+n,i,1Shl -,0); Repeat fori:=0 toTt Dos[i]:=D[i]; Fillchar (v,sizeof (v), false); Fillchar (F,sizeof (f),1); Inc (Flow,dfs (0,1Shl -)); IMP:=1Shl -; fori:=0 toTt Do if( notV[i]) and(F[I]<IMP) Thenimp:=F[i]; fori:=0 toTt Do if notV[i] ThenInc (DIS[I],IMP); untilimp=1Shl -; Writeln (ans);End.
View Code
BZOJ3876[AHOI2014] Spur plot