Main topic: Bare Optimal proportional ring
Direct two-point answer +SPFA This will be t because the data card SPFA
SPFA when the negative ring is very small will degenerate into bellman-ford time complexity is O (nm) (like O (n*m^2)? I forgot).
In another way, enumerate each point starting at each point Dfs returns true only along the edge search that can reduce the point dis to the point in the stack.
Expected complexity O (n^2) The worst Complexity O (2^n) This thing can pass me too drunk
#include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include < algorithm> #define M 3030#define EPS 1e-9#define INF 1e7using namespace std;struct abcd{int to,next;double f;} Table[10100];int head[m],tot;int n,m,t;double a[10100],dis[m];void Add (int x,int y) {Table[++tot].to=y;table[tot]. Next=head[x];head[x]=tot;} void DFS (int x) {static int v[m];int i;if (v[x]==t) throw (true); V[x]=t;for (I=head[x];i;i=table[i].next) if (dis[x]+table [i].f<dis[table[i].to]) {Dis[table[i].to]=dis[x]+table[i].f;dfs (table[i].to);} v[x]=0;} BOOL Judge (double x) {int i;for (i=1;i<=m;i++) table[i].f=a[i]-x;for (i=1;i<=n;i++) {Try{++t;memset (dis,0,sizeof DIS);D fs (i);} catch (bool) {return true;}} return false;} Double bisection () {int i;double l=inf,r=-inf;for (i=1;i<=m;i++) l=min (L,a[i]), R=max (R,a[i]), while (R-l>eps) { Double mid= (l+r)/2;if (Judge (mid)) R=mid;else L=mid;} Return (L+R)/2;} int main () {int i,x,y;cin>>n>>m;for (i=1;i<=m;i++) scanf ("%d%d%lf", &x,&amP;y,&a[i]), ADD (x, y), cout<<fixed<<setprecision (8) <<bisection () <<endl;return 0;}
Bzoj 1486 HNOI2009 min lap answer +dfs