The main topic: give a direction graph, the path length of the graph to the smallest average ring.
Train of thought: two points this answer, and then all the edge of the right to subtract the value of the two, for all nodes Dfs, the process is only in the direction of decreasing length of search, if the search back to their own, indicating that can reduce the bounds, otherwise ascending the nether.
Do not use SPFA to award negative rings, because they will be t.
CODE:
#include <cmath> #include <cstdio> #include <iomanip> #include <cstring> #include <iostream > #include <algorithm> #define MAX 3010#define maxe 10010#define INF 1e10#define EPS 1e-12using namespace std; int points,edges;double Len; int Head[max],total;int Next[maxe],aim[maxe];d ouble length[maxe]; inline void Add (int x,int y,double len) {next[++total] = head[x]; Aim[total] = y; Length[total] = len; HEAD[X] = total;} BOOL V[max];d ouble Mid,f[max]; void DFS (int x) {if (v[x]) throw true; V[x] = true; for (int i = head[x]; i; i = Next[i]) if (F[x] + length[i]-mid < F[aim[i]]) {F[aim[i]] = f[x] + Leng Th[i]-Mid; DFS (Aim[i]); } V[x] = false;} Double L =-inf,r = INF; int main () {cin >> points >> edges; for (int x,y,i = 1; i <= edges; ++i) {scanf ("%d%d%lf", &x,&y,&len); ADD (X,y,len); L = min (L,len); r = Max (R,len); } while (Fabs (r-l) > EPS) {mid = (L + r)/2.0; BOOL flag = FALSE; for (int i = 1; I <= points; ++i) {try {memset (f,0,sizeof (f)); memset (v,false,sizeof (v)); DFS (i); }catch (bool) {flag = true; Break }} if (flag) R = Mid; else L = mid; } if (Fabs (L) < EPS) cout << "0.00000000" << Endl; else cout << fixed << setprecision (8) << l << Endl; return 0;}
Bzoj 1486 hnoi 2009 min Circle DFS