裸题...平均权值最小的环....
注意$dfs-spfa$时$dfs(cl)$...不要写成$dfs(u)$
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
typedef long long ll;
const int N=,M=1e4+;
const double eps=1e-;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int n,m,u,v;
double w;
struct edge{
int v,ne;
double w;
}e[M];
int h[N],cnt=;
inline void ins(int u,int v,double w){
cnt++;
e[cnt].v=v;e[cnt].w=w;e[cnt].ne=h[u];h[u]=cnt;
}
double d[N],g;
int vis[N],cl;
bool dfs(int u){
vis[u]=cl;
for(int i=h[u];i;i=e[i].ne){
int v=e[i].v;double w=e[i].w-g;
if(d[v]>d[u]+w){
d[v]=d[u]+w;
if(vis[u]==vis[v]) return true;
else if(dfs(v)) return true;
}
}
vis[u]=;
return false;
}
bool NegativeCircle(double mid){
g=mid;
memset(vis,,sizeof(vis));
memset(d,,sizeof(d));
for(cl=;cl<=n;cl++) if(dfs(cl)) return true;
return false;
}
bool check(double mid){return NegativeCircle(mid);}
void solve(){
double l=-1e7,r=1e7;
while(r-l>eps){
double mid=(l+r)/2.0;
if(check(mid)) r=mid;
else l=mid;
}
printf("%.8lf",l);
}
int main(){
freopen("in","r",stdin);
n=read();m=read();
for(int i=;i<=m;i++){
u=read(),v=read();
scanf("%lf",&w);
ins(u,v,w);
}
solve();
}