/*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)