HDU 2962 Shortest circuit + two points

Source: Internet
Author: User

Test instructions: There is a height limit on the shortest road, to the starting point and maximum height, in order to meet the height of the maximum, shortest distance

Don't understand why enumerating all heights is not right

1#include <cstdio>2#include <cstring>3#include <algorithm>4 Const intMaxint=999999;5 intc[1005][1005][2],dist[1005],h[1005];6 using namespacestd;7 intN,line;8 inti,j,k;9 intSt,ed,mid;Ten intt=0; One intpath[1005]; A intvisit[1005]; - BOOLDijkstra () - { the     BOOLs[1005]; -       for(intI=1; i<=n;i++) -      { -s[i]=0; +              if(c[st][i][0]>=mid) -dist[i]=c[st][i][1]; +               Elsedist[i]=maxint; Apath[i]=St; at      } -s[st]=1; -       for(intI=1; i<n;i++) -      { -          inttemp=maxint; -          intu=St; in             for(intj=1; j<=n;j++) -                  if(!s[j]&&temp>dist[j]&&c[path[j]][j][0]>=mid) to                  { +temp=Dist[j]; -u=J; the                  } *            if(Temp==maxint) Break; $s[u]=1;Panax Notoginseng            if(u==ed)return true; -             for(intj=1; j<=n;j++) the                  if(!s[j]&&c[u][j][1]!=maxint&&c[u][j][0]>=mid) +                       if(dist[j]>dist[u]+c[u][j][1]) A                       { thedist[j]=dist[u]+c[u][j][1]; +path[j]=u; -                       } $      } $    return false; - } - intMain () the { - #ifndef Online_judgeWuyiFreopen ("1.in","R", stdin); the         #endif -      while(SCANF ("%d%d", &n,&line)!=eof&&n&&Line ) Wu     { -         inttot=1; Aboutmemset (H,0,sizeof(H)); $h[0]=0; -         if(t) printf ("\ n"); -printf"Case %d:\n",++t); -          for(i=1; i<=n;i++) A              for(j=1; j<=n;j++) +         { thec[i][j][1]= (i==j?0: maxint); -c[i][j][0]=-999999; $         } the          for(i=1; i<=line;i++) the         { the             intp,q,len,h; thescanf"%d%d%d%d",&q,&p,&h,&len); -             if(h==-1) in             { thec[p][q][0]=c[q][p][0]=maxint; thec[p][q][1]=c[q][p][1]=Len; About                 Continue; the             } the             if(c[p][q][0]<h) the             { +c[p][q][0]=c[q][p][0]=h; -c[p][q][1]=c[q][p][1]=Len; the             }Bayi         } the         inttall; thescanf"%d%d%d",&st,&ed,&tall); -         /*if (st==ed) -         { the printf ("Maximum height =%d\n", tall); the printf ("Length of shortest route = 0\n"); the continue; the         }*/ -         /*H[tot++]=tall; the sort (h,h+tot); the int ans=0; the bool flag=0;94 For (i=tot-1;i>=0;i--) the         { the if (h[i]>tall) continue; the Mid=h[i];98 if (Dijkstra ()) About             { - flag=1;101 ans=dist[ed];102 Break ;103             }104         }*/ the         intfirst=1;106         intans;107Mid= (First+tall) >>1;108          while(first<=tall)109         { the             if(Dijkstra ())111             { theans=dist[ed];113First=mid+1; the             } the             Else thetall=mid-1;117Mid= (First+tall) >>1;118         }119         if(tall==0) printf ("cannot reach destination\n"); -         Else121         {122printf"Maximum height =%d\n", tall);123printf"length of shortest route =%d\n", ans);124         } the     }126     return 0;127}

HDU 2962 Shortest circuit + two points

Related Article

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.