1 #include <algorithm>
2 #include <cstdio>
3 #include <queue>
4
5 using namespace std;
6
7 const int N(1100000+15);
8 queue<int>que;
9 int n,m,u,v,w,rudu[N],chudu[N];
10 double f[N];
11 int head[N],edgesum;
12 struct Edge
13 {
14 int from,to,next,dis;
15 Edge(int from=0,int to=0,int next=0,int dis=0) :
16 from(from),to(to),next(next),dis(dis) {}
17 }edge[N];
18
19 int ins(int from,int to,int dis)
20 {
21 edge[++edgesum]=Edge(from,to,head[from],dis);
22 return head[from]=edgesum;
23 }
24
25 int main()
26 {
27 scanf("%d%d",&n,&m);
28 for(int i=1;i<=m;i++)
29 {
30 scanf("%d%d%d",&u,&v,&w);
31 chudu[u]++; rudu[u]++;
32 ins(v,u,w);
33 }
34 for(int i=1;i<=n;i++)
35 if(!rudu[i]) que.push(i);
36 while(!que.empty())
37 {
38 u=que.front();
39 que.pop();
40 for(int i=head[u];i;i=edge[i].next)
41 {
42 v=edge[i].to;
43 f[v]+=1.0*(f[u]+edge[i].dis)/chudu[v];
44 rudu[v]--;
45 if(!rudu[v]) que.push(v);
46 }
47 }
48 printf("%.2lf",f[1]);
49 return 0;
50 }