The main idea: there is a T (t<=100) bar without the edge connection two points, the S to e just through the N (n<=10^7) path of the minimum distance.
The first reaction layer chart, but a look at N on the crazy, will not write. After reading the puzzle to know can play like this ...
First there are 100 sides with a maximum of 200 points, but the points numbered to 1000, so discretization a bit.
any positive integer can be added with a power of 2, so first turn N into 2, and the bitwise considerations. Dist[i][j][k] means that the shortest distance from J to K is just passing through the 2^i bar, then dist[i,j,k]=min{dist[i-1][j][l]+dist[i-1][l][k]}. With a similar quick power method, if the 2 binary n This bit is 1, the answer array G and Dist run Floyd (Min{g[i-1][j][l]+dist[i-1][l][k]}), otherwise dist himself and run (min{dist[i-1][j][l ]+DIST[I-1][L][K]}) so that the sub-G is the minimum distance to run the N path .
The code is as follows:
typeMap=Array[1.. +,1.. +] ofLongint;varN,t,s,e,i,j,k,len,x,y,tot:longint; C,d,g:Array[1.. +,1.. +] ofLongint; Num:Array[1.. +] ofLongint;procedureMergevara,b:map);varI,j,k:longint;beginFillchar (C,sizeof (c), the); fork:=1 toTot Do fori:=1 toTot Do forj:=1 toTot Do ifC[I,J]>A[I,K]+B[K,J] ThenC[i,j]:=a[i,k]+B[k,j]; A:=C;End;procedureWork ;beginFillchar (G,sizeof (g), the); fori:=1 toTot Dog[i,i]:=0; whileN>0 Do begin ifN and 1=1 Thenmerge (g,d); Merge (D,d); N:=n>>1; End; Writeln (G[num[s],num[e]);End;beginreadln (n,t,s,e); Fillchar (d,sizeof (d), the); fori:=1 toT Do beginreadln (len,x,y); ifnum[x]=0 Then beginInc (TOT); Num[x]:=tot; End; ifnum[y]=0 Then beginInc (TOT); Num[y]:=tot; End; D[num[x],num[y]]:=len;d[num[y],num[x]]:=Len; End; work;End.
View Code
bzoj1706: [Usaco2007 nov]relays Cow relay run (floyd+ new posture)