#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,double> PII;
const int inf = numeric_limits<int>::max();

double p;
int n;
vector< vector<PII> > G;
double dp[100100];
double dp2[100100];
int visited[100100];

double calc_dp(int node){
  visited[node] = 1;
  double ret = 0;
  for(int i = 0;i < (int)G[node].size();++i){
    if(!visited[G[node][i].first]){
      ret += p*(G[node][i].second
                + calc_dp(G[node][i].first));
    }
  }
  return dp[node] = ret;
}

double calc_dp2(int node){
  visited[node] = 1;
  double ret = dp[0];
  for(int i = 0;i < (int)G[node].size();++i){
    if(!visited[G[node][i].first]){
      ret += 
        p*(G[node][i].second + calc_dp2(G[node][i].first));
    }
  }
  return dp2[node] = ret;
}

int main(void){
  cin >> p >> n;
  G.resize(n);
  for(int i = 0;i < n-1;++i){
    int x,y;
    double c;
    cin >> x >> y >> c;
    --x;--y;
    G[x].push_back(PII(y,c));
    G[y].push_back(PII(x,c));
  }
  fill(dp,dp+100100,0);
  fill(dp2,dp2+100100,0);
  fill(visited,visited+100100,0);
  calc_dp(0);
  fill(visited,visited+100100,0);
  calc_dp2(0);
  cout << setprecision(15) << dp2[0] << endl;
  return 0;
}