/*  -*- coding: utf-8 -*-
 *
 * 2807.cc: Fractal Tree
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef pair<int,int> pii;
typedef vector<pii> vpii;

struct Stat {
  int i, prt;
  double p;
  Stat() {}
  Stat(int _i, int _prt, double _p): i(_i), prt(_prt), p(_p) {}
};

/* global variables */

vpii nbrs[MAX_N];

/* subroutines */

/* main */

int main() {
  double p;
  int n;
  scanf("%lf%d", &p, &n);

  for (int i = 1; i < n; i++) {
    int x, y, c;
    scanf("%d%d%d", &x, &y, &c);
    x--, y--;
    nbrs[x].push_back(pii(y, c));
    nbrs[y].push_back(pii(x, c));
  }

  queue<Stat> q;
  q.push(Stat(0, -1, 1.0));
  double t = 0.0;

  while (! q.empty()) {
    Stat u = q.front(); q.pop();
    vpii nbru = nbrs[u.i];
    double vp = u.p * p;

    for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int &vi = vit->first, &vc = vit->second;
      if (vi != u.prt) {
	t += vc * vp;
	q.push(Stat(vi, u.i, vp));
      }
    }
  }
  //printf("t=%lf\n", t);

  q.push(Stat(0, -1, 1.0));
  double ans = t;
  
  while (! q.empty()) {
    Stat u = q.front(); q.pop();
    vpii nbru = nbrs[u.i];
    double vp = u.p * p;
    ans += t * u.p;

    for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int &vi = vit->first;
      if (vi != u.prt)
	q.push(Stat(vi, u.i, vp));
    }
  }
  printf("%.10lf\n", ans);

  return 0;
}

