The fate of mung bean frog

Source: Internet
Author: User

"Title description"

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 how much.

"Input description"

The first line: two integers n, m, representing the graph has n points, M edge;
The second line to line 1+m: 3 integers A, B, c for each line, representing a forward edge with a length of C from a to B.

"Output description"

The expected value of the total length from the starting point to the end path, rounding retains two decimal places.

"Sample Input"

4 4
1 2 1
1 3 2
2 3 3
3 4 4

"Sample Output"

7.00

"Data range and Tips"

For 20% data: N <= 100;
For 40% data: N <= 1000;
For 60% data: N <= 10000;
For data of 100%: N <= 100000,m<=2*n.

The fate 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.