"Hdoj" 3660 Alice and Bob ' s trip

Source: Internet
Author: User

is a basic DFS. The key issue is that the c/c++/g++ light input is timed out. Or write Java over, after all, the time limit is 4s. All gave up hope, did not think it was true.

1 Importjava.lang.*;2 ImportJava.io.*;3 ImportJava.util.*;4 5 6  Public classMain {7     8      Public Static voidMain (string[] args)throwsjava.lang.Exception {9InputStream InputStream =system.in;TenOutputStream OutputStream =System.out; OneInputreader in =NewInputreader (inputstream); APrintWriter out =NewPrintWriter (outputstream); -Taska Solver =NewTaska (); - Solver.solve (in, out); the out.close (); -     } - } -  + classTaska { -      Public Final Static intMAXV = (int) (5e5+5); +      Public Final Static intINF = 0x3f3f3f3f; A     int[] V =New int[MAXV]; at     int[] W =New int[MAXV]; -     int[] NXT =New int[MAXV]; -     int[] head =New int[MAXV]; -     intm, N, L, R; -      -     voidinit () { inm = 0; -Arrays.fill (Head,-1); to     } +      -     voidAddedge (intUintVintW) { theV[M] =v; *W[M] =W; $NXT[M] =Head[u];Panax NotoginsengHead[u] = m++; -     } the      +      Public voidsolve (Inputreader in, printwriter out) { A         inti; the         intu, V, W; +         intans; -          $          while(true) { $             Try { -n =in.nextint (); -}Catch(RuntimeException e) { the                  Break; -             }WuyiL =in.nextint (); theR =in.nextint (); - init (); Wu              for(I=1; i<n; + +)i) { -U =in.nextint (); Aboutv =in.nextint (); $W =in.nextint (); - Addedge (U, V, W); -             } -Ans = DFS (0, 0, 0); A             if(ans = =INF) +Out.println ("Oh, My god!"); the             Else - out.println (ans); $         } the     } the      the     Private intDfsintUintLenintNow ) { the         intAns =-1; -          in         if(Head[u] = =-1) the             return0; the         intI, V, W; About          the          for(I=head[u]; i!=-1; i=Nxt[i]) { thev =V[i]; theW =W[i]; +             intTMP = DFS (V, len+w, now^1) +W; -             if(TMP = =INF) the                 Continue;Bayi             if(Tmp>=l-len && tmp<=r-Len) { the                 if(now = = 0) { the                     if(Ans==-1 | | tmp>ans) -Ans =tmp; -}Else { the                     if(Ans==-1 | | tmp<ans) theAns =tmp; the                 } the             } -         } the          the         if(ans = =-1) the             returnINF;94         returnans; the     } the } the 98 classInputreader { About      PublicBufferedReader Reader; -      PublicStringTokenizer Tokenizer;101     102      PublicInputreader (InputStream stream) {103Reader =NewBufferedReader (NewInputStreamReader (stream), 32768);104Tokenizer =NULL; the     }106     107      PublicString Next () {108          while(tokenizer==NULL|| !Tokenizer.hasmoretokens ()) {109             Try { theTokenizer =NewStringTokenizer (Reader.readline ());111}Catch(IOException e) { the                 Throw NewRuntimeException (e);113             } the         } the         returnTokenizer.nexttoken (); the     }117     118      Public intNextint () {119         returnInteger.parseint (Next ()); -     }121}

"Hdoj" 3660 Alice and Bob ' s trip

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.