f[i]表示走到i点的期望。。然后就没然后了。。
#include<iostream>
#include<cstdio>
using namespace std;
int n,m,cnt;
int ind[100005],head[100005];
bool vis[100005];
double f[100005];
int next[200005],list[200005],key[200005];
inline int read()
{
int a=0,f=1; char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1; c=getchar();}
while (c>='0'&&c<='9') {a=a*10+c-'0'; c=getchar();}
return a*f;
}
inline void insert(int x,int y,int z)
{
ind[x]++;
next[++cnt]=head[x];
head[x]=cnt;
list[cnt]=y;
key[cnt]=z;
}
double dfs(int x)
{
if (vis[x]) return f[x];
vis[x]=1;
for (int i=head[x];i;i=next[i])
f[x]+=dfs(list[i])+key[i];
if (ind[x]) f[x]/=ind[x];
return f[x];
}
int main()
{
n=read(); m=read();
for (int i=1;i<=m;i++)
{
int u=read(),v=read(),w=read();
insert(u,v,w);
}
printf("%.2lf",dfs(1));
return 0;
}