#include <bits/stdc++.h>

using namespace std;

const bool debug = true;
#define dbg(...) if(debug) printf(__VA_ARGS__)
#define print(var) if (debug) cout << #var << " = " << var << endl

namespace {
    using real = long double;
    struct Edge {
        int from, to, cost;
        Edge() {}
        Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
    };
    real p;
    int N;
    vector<vector<Edge>> G;
    void input() {
        cin >> p >> N;
        G.resize(N);
        for (int i = 0; i < N - 1; i++) {
            int x, y, c; cin >> x >> y >> c;
            x--; y--;
            G[x].emplace_back(x, y, c);
            G[y].emplace_back(y, x, c);
        }
    }

    void solve() {
        real e; {
            function<real(int, int)> dfs = [&](int v, int prev) {
                // returns expected value of cost.:
                real ret = 0;
                for (auto& next : G[v]) {
                    if (next.to == prev) continue;
                    ret += p * (next.cost + dfs(next.to, v));
                }
                return ret;
            };
            e = dfs(0, -1);
        }
        real ans = 0; {
            function<void(int, int, real)> dfs = [&](int v, int prev, real prob) {
                ans += prob * e;
                for (auto& next : G[v]) {
                    if (next.to == prev) continue;
                    ans += prob * p * next.cost;
                    dfs(next.to, v, prob * p);
                }
            };
            dfs(0, -1, 1.0);
        }
        cout << setprecision(12) << fixed << ans << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}


