#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
struct edge{int to,cost;};
edge e;
vector<edge>v[100001];
double ans,t,p,c;
int dis[100001],a,b,n;
bool used[100001];
void dfs(int x,int d){
	used[x]=1;
	dis[d]++;
	r(i,v[x].size())
	  if(!used[v[x][i].to]){
	  	t+=v[x][i].cost*pow(p,(double)d+1);
	  	dfs(v[x][i].to,d+1);
	  }
	 if(!d){
	 	ans=t;
	    r(i,n)ans+=t*pow(p,(double)(i))*dis[i];
	    printf("%.9f\n",ans);
	 }
}
int main(){
	cin>>p>>n;
	r(i,n-1){
		cin>>a>>b>>c;
		a--;b--;
		e.to=b,e.cost=c;
		v[a].push_back(e);
		e.to=a;
		v[b].push_back(e);
	}
	dfs(0,0);
}