It's easy to see 0/1 score planning
But...... I forgot how to do it for a long time without writing.
Two points +SPFA negative ring.
01 Fractional Planning Is this: there is a pile of items, each with a value of a[i], and the price b[i]. The σa[i]/σb[i to be taken from all items is the maximum value.
Set K as a possible value, then make D[i]=a[i]-k*b[i]. In this question A[i] is the right side of the I, B[i] are 1
If d[i]>0, then it is clear that the value of K can be increased again.
This is the optimal ratio loop.
Two points a K, and then re-build the map, the weight is d[i]. Then enumerate each point to run SPFA to award negative rings. If you have a negative ring, you can't, otherwise update the answer
#include <cstdio> #include <iostream> #include <cstring> #include <cstdlib> #include < algorithm> #include <cmath> #include <queue> #include <deque> #include <set> #include <map > #include <ctime> #define LL long long#define INF 0x7ffffff#define pa pair<int,int> #define Pi 3.1415926535897932384626433832795028841971#define EPs 1e-10using namespace std;inline ll read () {LL X=0,f=1;char ch=get char (); while (ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} inline void Write (LL a) {if (a<0) {printf ("-"); a=-a;} if (a>=10) write (A/10); Putchar (a%10+ ' 0 ');} inline void Writeln (LL a) {write (a);p rintf ("\ n");} struct edge{int to,next;double v,v0;} E[100010];int n,m,cnt;bool fnd,mrk[100010];int head[100010];d ouble dist[100010];d ouble l=-1000000000.0,r= 1000000000.0,ans=0.0;inline void ins (int u,int v,double W) {E[++cnt].to=v;e[cnt].v0=w;e[cnt].next=head[U];head[u]=cnt;} inline void Spfa (int x) {mrk[x]=1;for (int i=head[x];i;i=e[i].next) if (DIST[E[I].TO]>DIST[X]+E[I].V) {if (Mrk[e[i]. To]) {Fnd=1;return;} DIST[E[I].TO]=DIST[X]+E[I].V;SPFA (e[i].to); if (FND) return;} mrk[x]=0;} inline bool Jud () {Fnd=0;memset (mrk,0,sizeof (MRK)); memset (dist,0,sizeof (Dist)); for (int i=1;i<=n;i++) {SPFA (i); if (FND) return 0;} return 1;} int main () {n=read (); M=read (); for (int i=1;i<=m;i++) {int x=read (), Y=read ();d ouble z;scanf ("%lf", &z); Ins (x, Y, Z );} while (r-l>=eps) {double mid= (l+r)/2;for (int. i=1;i<=n;i++) for (int j=head[i];j;j=e[j].next) e[j].v= (e[j].v0-mid ); if (Jud ()) {ans=mid;l=mid;} else R=mid;} printf ("%.8lf\n", ans);}
bzoj1486 [HNOI2009] min. circle