#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define int long long
#define double long double
const int N=2e5+7;
const int mod=1e9+7;
const int inf=4e18;
mt19937 rnd(time(0));
clock_t start,over;
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-'0',ch=getchar();}return x*f;}
inline void write(int x){if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);putchar(x%10+'0');return;}
int dout[N];
double f[N];
struct node{
int v,w;
};
vector<node>g[N];
void dfs(int x){
double res=0;
for(auto &[y,w]:g[x]){
dfs(y);
int k=g[x].size();
res+=(f[y]+w)*1.0/dout[x];
}
f[x]=res;
}
void solve(){
int n,m;cin>>n>>m;
for(int i=1;i<=n;i++){
int u,v,w;cin>>u>>v>>w;
dout[u]++;
g[u].push_back({v,w});
}
dfs(1);
double ans=f[1];
cout<<fixed<<setprecision(2)<<ans<<'\n';
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int _=1;
while(_--)solve();
}