#include using namespace std; using ll = long long; using pll = pair; #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); const ll MOD1000000007 = 1000000007; const ll MOD998244353 = 998244353; const ll MOD[3] = {999727999, 1070777777, 1000000007}; const ll LINF = 1LL << 60LL; const int IINF = (1 << 30) - 1; struct union_find{ vector par; vector siz; union_find(int n) : par(n), siz(n, 1){ for(int i=0; i> n >> m; vector> es(m); for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; a--; b--; c--; es[i] = {c, a, b}; } sort(all(es)); union_find uf(n); vector init_cnt(6, 0); for(int i=0; i, ld> dp; dp[{0, 0, 0, 0, 0, 0}] = 0; function)> dfs = [&](vector cnt){ if(dp.find(cnt) != dp.end()) return; vector pre(6, 0); pre[0] = -1; if(cnt[0] > 0) pre[0] = 0; for(int i=1; i<6; i++){ pre[i] = pre[i-1]; if(cnt[i] > 0) pre[i] = i; } int c = 0; dp[cnt] = 1; for(int i=0; i<6; i++){ if(pre[i] == -1){ c++; }else{ vector nxt = cnt; nxt[pre[i]]--; dfs(nxt); dp[cnt] += dp[nxt]/(ld)6; nxt[pre[i]]++; } } dp[cnt] /= (1 - (ld)c/(ld)6); }; dfs(init_cnt); cout << fixed << setprecision(10) << dp[init_cnt] << '\n'; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int T=1; //cin >> T; while(T--) solve(); }