BZOJ1001 Wolf Catch the rabbit finally!

Source: Internet
Author: User

Time is too late, first put the code! Have time to write again.

Good bitter, WA several times, there is another re, a tle.

Although the main use of the algorithm and data are provided by senior. is too weak, too naïve.

1#include <cstdio>2#include <iostream>3#include <queue>4#include <cstring>5 #defineMAXN 21000096 #defineRep (i,j,k) for (int i = j; I <= K; i++)7 using namespacestd;8 9 intRead ()Ten { One     ints =0, t =1;Charc =GetChar (); A      while( !IsDigit (c)) { -         if(c = ='-') T =-1; c =GetChar (); -     } the      while(IsDigit (c)) { -s = S *Ten+ C-'0'; c =GetChar (); -     }  -     returnS *T; + } -  + intD[MAXN], N, M, SX, TX; A BOOLDONE[MAXN] = {0};  at  - structnode{ - intd, u; - BOOL operator< (Constnode& RHS)Const{ -         returnD >RHS.D; -      } in }; -  to structedge{ + intto, key; -edge*Next; the }; *  $Edge *pt, edges[maxn*3], *HEAD[MAXN];Panax Notoginseng  - voidAdd_edge (intXintYintval) { thePt->to = Y;pt->key =Val; +Pt->next =Head[x]; AHEAD[X] = pt++; thePt->to = x, pt->key=Val; +Pt->next =Head[y]; -Head[y] = pt++;  $ } $Priority_queue<node>Q; -  - voidDijkstra () the { -memset (D,127,sizeof(d));WuyiD[SX] =0; theQ.push (node) {0, SX}); -       while( !Q.empty ()) { WuNode x =Q.top (); Q.pop (); -         intU =x.u; About         if(Done[u])Continue; $Done[u] =1; -          for(edge*i = head[u]; i; i = i->next) { -             inty = i->to, key = I->key; -             if(D[y] > d[u]+key) { AD[y] = d[u]+key; + Q.push (node) {d[y],y}); the             } -         } $      } the } the  the intMain () the { -     //freopen ("OUT.txt", "w", stdout); inPT =edges; then = Read (), M =read (); theSX =0, TX = (n1) * (M-1) *2+1; AboutRep (I,0, N-1) { the       intxx = (2*m-2)*i; the       intXY = (2*m-2) * (I-1); theRep (J,1, M-1){ +          intx =read (); -          if( !i) { theAdd_edge (xx+2*j,tx,x);Bayi             //cout<<tx<< "" <<xx+2*j+1<< "" <<x<<endl; the          }  the          Else if(i = = n1 ) { -Add_edge (sx,xy+2*j-1, x); -             //cout<<xy+2*j<< "" <<sx<< "" <<x<<endl; the          } the          Else{ theAdd_edge (xx+2*j,xy+2*j-1, x); the             //cout<<xy+2*j<< "" <<xx+2*j+1<< "" <<x<<endl; -          } the       } the    } theRep (I,0, N-2){94       intxx =2* (M-1)*(i); theRep (J,1, M) { the          intx =read (); the          if(J = =1 ){98Add_edge (sx,xx+2*j-1, x); About             //cout<<sx<< "" <<xx<< "" <<x<<endl; -          } 101          Else if(J = =m) {102Add_edge (tx,xx+2*j-2, x);103             //cout<<tx<< "" <<xx+2*j-1<< "" <<x<<endl;104          } the          Else {106Add_edge (xx+2*j-2, xx+2*j-1, x);107             //cout<<xx+2*j<< "" <<xx+2*j-1<< "" <<x<<endl;108          }109       } the    }111Rep (I,0, N-2){ the      intxx =2* (M-1)*(i);113Rep (J,1, M-1){ the         intx =read (); theAdd_edge (xx+2*j,xx+2*j-1, x); the         //cout<<xx+2*j<< "" <<xx+2*j+1<< "" <<endl;117      }118    }119 Dijkstra (); -cout<<d[tx]<<Endl;121    return 0;122}

BZOJ1001 Wolf Catch the rabbit finally!

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.