You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
const int N = 1e5 + 10, M = N << 1;
|
|
|
|
|
|
|
|
|
|
int n, m;
|
|
|
|
|
int h[N], e[M], ne[M], w[M], idx;
|
|
|
|
|
int out[N];
|
|
|
|
|
double f[N];
|
|
|
|
|
|
|
|
|
|
void add(int a, int b, int c) {
|
|
|
|
|
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
|
|
|
|
|
}
|
|
|
|
|
double dfs(int u) {
|
|
|
|
|
if (f[u] >= 0) return f[u]; // 如果u点计算过,记忆化搜索返回结果值
|
|
|
|
|
f[u] = 0; // 初始化为0,准备开始填充
|
|
|
|
|
for (int i = h[u]; ~i; i = ne[i]) {
|
|
|
|
|
int j = e[i];
|
|
|
|
|
f[u] += (w[i] + dfs(j)) / out[u];
|
|
|
|
|
}
|
|
|
|
|
return f[u];
|
|
|
|
|
}
|
|
|
|
|
int main() {
|
|
|
|
|
memset(h, -1, sizeof h);
|
|
|
|
|
cin >> n >> m;
|
|
|
|
|
while (m--) {
|
|
|
|
|
int a, b, c;
|
|
|
|
|
cin >> a >> b >> c;
|
|
|
|
|
add(a, b, c);
|
|
|
|
|
out[a]++;
|
|
|
|
|
}
|
|
|
|
|
memset(f, -1, sizeof f);
|
|
|
|
|
printf("%.2lf\n", dfs(1));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|