2488 The home of mung bean Frog
time limit: 1 sspace limit: 64000 KBtitle level: Golden Gold SolvingView Run ResultsTitle Description
Description
With the new version of Baidu space on-line, blog pet mung Bean Frog completed its mission, to find its new destination.
Give a direction-free graph with a starting point of 1 ending to n, each side having a length, and starting from the beginning to reach all points, all points can also reach the end point. The mung bean frog starts from the starting point and goes to the end.
At each vertex, if there is a road where K leaves the point, the mung bean Frog can choose any route to leave the point, and the probability of going to each road is 1/k.
Now mung bean frog want to know, from the starting point to the end of the path through the total length of the expectation is what?
Enter a description
Input Description
First line: Two integers n m, representing n points, M edges in the graph
The second line to line 1+m: 3 integers a b c each line, representing a to B with a length of C with a forward edge
Output description
Output Description
The expected value of the total length from the starting point to the end path, rounding retains two decimal places.
Sample input
Sample Input
4 4
1 2 1
1 3 2
2 3 3
3 4 4
Sample output
Sample Output
7.00
Data range and Tips
Data Size & Hint
For 20% of data n<=100
For 40% of data n<=1000
For 60% of data n<=10000
For 100% of data n<=100000,m<=2*n
Source: Nescafe 19
Category labels
Tags Click here to expandThe theory of dynamic programming topological sort diagram
#include <cstdio>#include<iostream>#include<vector>using namespacestd;#defineN 1000100Vector<int>Road[n];vector<int>Dis[n];intn,m;DoubleF[n];DoubleTpintx) { if(x==n)return 0; if(F[x])returnF[x]; for(intI=0; I<road[x].size (); i++) {F[x]+ = (TP (Road[x][i]) +dis[x][i])/road[x].size (); }//topology not visible, direct DFS returnf[x];}intMain () {scanf ("%d%d",&n,&m); for(intI=1, a,b,c;i<=m;i++) {scanf ("%d%d%d",&a,&b,&c); Road[a].push_back (b);//structure can also be writtenDis[a].push_back (c);//Vector more Convenient} printf ("%.2lf\n", TP (1)); return 0;}
2488 the home of mung bean frog