Http://livearchive.onlinejudge.org/index.php? Option = com_onlinejudge & Itemid = 8 & page = show_problem & problem = 3074
I have written this type of question before. Why do I have to worry about it during the competition,
We can use dis [a] [B] to change the side B to a point. Then we actually add some edges to the edges in the source image.
For example, if a is connected to C in the source image, we add the edges of DIS [C] [B + 1] and DIS [a] [B, the weight of this edge is 0, but this edge must be added after DIS [a] [B.
Then traverse dis [N] [I ..
# Include <iostream> # Include <Stdio. h> # Include < String . H> # Include <Algorithm># Include <Queue> # Include <Vector> # Define Maxn 1000 # Define INF ~ 0u> 1; Using Namespace STD; Int N, m, cost; vector < Int > Node [maxn]; Int Map [maxn] [maxn]; Int Visit [maxn] [maxn]; Int Dis [maxn] [maxn]; Void Init (){ Int A, B, C; memset (map, 0 , Sizeof (MAP )); For ( Int I = 0 ; I <= N; I ++ ) Node [I]. Clear (); For (Int I = 0 ; I <m; I ++ ) {CIN > A> B> C; node [A]. push_back (B); map [a] [B] = C ;}} Void Solve () {queue <Pair < Int , Int > Q; // Leave a space For ( Int I =0 ; I <= N; I ++ ) For ( Int J = 0 ; J <= N; j ++ ) Dis [I] [J] = INF; memset (visit, 0 , Sizeof (Visit); DIS [ 1 ] [ 0 ] = 0 ; Q. Push (make_pair ( 1 , 0 ); Visit [ 1 ] [ 0 ] = 1 ; While (! Q. Empty ()){ Int A = Q. Front (). First, B = Q. Front (). Second; q. Pop (); // Team-out For ( Int I =0 ; I <node [A]. Size (); I ++ ) // If (! Visit [node [a] [I] [B]) { If (DIS [node [a] [I] [B]> dis [a] [B] + Map [a] [node [a] [I]) {dis [node [a] [I] [B] = Dis [a] [B] + map [a] [node [a] [I]; // Relaxed If (! Visit [node [a] [I] [B]) // Join the queue as long as it is not in the queue {Visit [node [a] [I] [B] = 1 ; Q. Push (make_pair (node [a] [I], B ));}} If (DIS [node [a] [I] [B + 1 ]> Dis [a] [B]) {dis [node [a] [I] [B + 1 ] = Dis [a] [B]; If (! Visit [node [a] [I] [B + 1 ]) {Visit [node [a] [I] [B +1 ] = 1 ; Q. Push (make_pair (node [a] [I], B + 1 ));} // The queue is push. } Visit [a] [B] = 0 ; // Outbound tag } For ( Int I = 0 ; I <= N; I ++ ) If (DIS [N] [I] <= Cost) {cout <I <Endl; Break ;}} Int Main (){ While (CIN> N> m> Cost ){ If (! (N + M + cost )) Break ; Init (); solve ();} Return 0 ;}