#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)



double P;
int N;
vector<pair<int, int>> E[101010];
//-----------------------------------------------------------------------------------
double dfs(int cu, int pa = -1) {
	double ret = 0;
	for (auto p : E[cu]) if (p.first != pa) {
		double ex = dfs(p.first, cu) + p.second;
		ret += ex * P;
	}
	return ret;
}
//-----------------------------------------------------------------------------------
double ex = 0;
double dfs2(int cu, int pa = -1) {
	double ret = ex;
	for (auto p : E[cu]) if (p.first != pa) {
		double ex = dfs2(p.first, cu) + p.second;
		ret += ex * P;
	}
	return ret;
}
//-----------------------------------------------------------------------------------
int main() {
	cin >> P >> N;
	rep(i, 0, N - 1) {
		int x, y, c; scanf("%d%d%d", &x, &y, &c);
		E[x].push_back({ y, c });
		E[y].push_back({ x, c });
	}

	ex = dfs(1);
	double ans = dfs2(1);

	printf("%.10f\n", ans);
}