UV 5073-test case tweaking

Source: Internet
Author: User

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 ;}

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.