#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int N;
double P;

struct edge {
	int to;
	double cost;
};
vector<edge> G[100000];

double s;

double dfs(int v, int par) {
	double sum = s;
	for(auto e : G[v]) {
		if(e.to == par) continue;
		sum += P * (e.cost + dfs(e.to, v));
	}
	return sum;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> P >> N;
	for(int i = 0; i < N - 1; i++) {
		int x, y;
		double c;
		cin >> x >> y >> c;
		x--, y--;
		G[x].push_back({ y, c });
		G[y].push_back({ x, c });
	}

	s = dfs(0, -1);
	cout << fixed << setprecision(15) << dfs(0, -1) << endl;
}