#include<iostream>
#include<cmath>
#include<vector>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

#define MAX 100100

struct Edge {
  int s,w;
};

int V;
vector<Edge> G[MAX];
double p;

double dfs(int cur,int pre,double coef=0.0) {
  double ex = 0;
  rep(i,(int)G[cur].size()) {
    Edge &e = G[cur][i];
    if( e.s == pre ) continue;
    ex +=  p * ( ( ( e.w + coef ) + dfs(e.s,cur,coef) ) ) ;
    //ex += ( dfs(e.s,cur,coef) + p * coef * (double)e.w );
  }
  return ex;
}

void compute() {
  double X = dfs(0,-1);
  printf("%.10f\n",dfs(0,-1,X)+X);
}

int main() {
  cin >> p;
  cin >> V;
  rep(i,V-1) {
    int a,b,c;
    cin >> a >> b >> c;
    --a, -- b;
    G[a].push_back((Edge){b,c});
    G[b].push_back((Edge){a,c});
  }
  compute();
  return 0;
}