2488 the home of mung bean frog

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.