#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pii pair<int,int>
#define ff first
#define ss second
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pb push_back
const int M = 100010;
int n, m, k, T;
inline int read()
{
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
return x*f;
}
vector<pii> mp[M];
double dp[M];// dp[i]表示从i到n的期望长度
int out[M];// 出度
bool vis[M];
void dfs(int x,int n){
if(vis[x])return;
vis[x]=true;
double sum=0.0;
for(auto &[y,w]:mp[x]){
dfs(y,n);
sum+=dp[y]+w;// 从u到v的期望 = w + 从v到n的期望
}
if(out[x]>0){
dp[x]=sum/out[x];// 平均期望
}
}
signed main()
{
n=read(),m=read();
int x,y,v;
for(int i=0;i<m;++i){
x=read(),y=read(),v=read();
mp[x].pb({y,v});
out[x]++;
}
dfs(1,n);
cout<<fixed<<setprecision(2)<<dp[1];
return 0;
}