Codevs 1183 Muddy Roads (binary +spfa+ differential constraints)

Source: Internet
Author: User

/*Two-point answer (note accuracy) for each answer (S1+S2+S3 ...) /(T1+t2+t3 ...) >=ans when the ANS has a larger space for the above inequalities if the enumeration of each road appears too violent to degenerate into: S1-t1*ans+s2-t2*ans+s3-t3*ans ... >=0 differential constraints run the longest way if dis[n]>0 or have a positive ring (beginning this forget) ans is legal*/#include<iostream>#include<cstdio>#include<cstring>#include<queue>Const Doublejing=0.0001;using namespacestd;Doubles[ the][ the],t[ the][ the],ans,a[ the][ the],dis[ the];intn,f[ the],c[ the],falg;voidSPFA (intSt) {memset (F,0,sizeof(f)); memset (DIS,-0x3f,sizeof(DIS)); Queue<int>Q; Q.push (ST); f[st]=1;d is[st]=0, c[st]=1;  while(!Q.empty ()) {          intk=Q.front ();          Q.pop (); if(c[k]>N) {falg=1; Break; }           for(intI=1; i<=n;i++)            if(s[k][i]&&dis[i]<dis[k]+A[k][i]) {Dis[i]=dis[k]+A[k][i]; if(f[i]==0) {C[i]=c[k]+1;                  Q.push (i); F[i]=1; }} F[k]=0; }}BOOLCheckDoublex) {     for(intI=1; i<=n;i++)       for(intj=1; j<=n;j++) A[i][j]=s[i][j]-x*T[i][j]; Falg=0; SPFA (1); if(dis[n]>0|| falg==1)return 1; Else return 0;}intMain () {CIN>>N;  for(intI=1; i<=n;i++)       for(intj=1; j<=n;j++) Cin>>S[i][j];  for(intI=1; i<=n;i++)       for(intj=1; j<=n;j++) Cin>>T[i][j]; DoubleL=0, r= -;  while(r-l>Jing) {          DoubleMid= (L+R)/2; if(check (mid)) {ans=mid; L=mid; }        ElseR=mid; } printf ("%.3f", ans); return 0;}

Codevs 1183 Muddy Roads (binary +spfa+ differential constraints)

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.