#include<bits/stdc++.h> #define N 112345 usingnamespacestd;
inlineintread(){ int x=0; int sign=1; char c=getchar(); while(c>'9' c<'0') {if (c=='-') sign=-1;c=getchar();} while(c>='0' && c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();} return x*sign; } vector<int> g[N]; vector<int> weight[N]; vector<int> topo; int in_deg[N]; double point_pr[N]; int n, m;
voidtopo_sort(){ queue<int> q; q.push(1); while(!q.empty()){ int u = q.front(); q.pop(); topo.push_back(u); for (unsignedint i = 0; i < g[u].size(); i++){ int v = g[u][i]; in_deg[v]--; if (in_deg[v] == 0){ q.push(v); } } } }
double ans = 0.0; voidcalc(){ point_pr[1] = 1.0; for(unsignedint i = 0; i < topo.size(); i++){ int u = topo[i]; int k = g[u].size(); for (int j = 0; j < k; j++){ int v = g[u][j]; int w = weight[u][j]; point_pr[v] += point_pr[u] / k; ans += (w * point_pr[u]) / k; } } }
intmain(){ //freopen("4316.in", "r", stdin); n = read(), m = read(); for (int i = 1; i <= m; i++){ int u = read(), v = read(), w = read(); g[u].push_back(v); weight[u].push_back(w); in_deg[v]++; }