The end of "bzoj3036" mung bean Frog

Source: Internet
Author: User

Title Description

With the new version of Baidu space offline, blog pet mung Bean Frog completed its mission, to find its new destination.

A connected graph with a direction-free loop is given, where the starting point is 1 and the end is N, and each edge has a length. 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?

Input

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

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

Tips

For 100% of data n<=100000,m<=2*n

SolvingExpect DP water problems together. F[i] represents the desired length from I to N (a forward loop-free connected graph). Be careful except for 0.
1#include <cstdio>2 #defineN 1000013 intHead[n], To[n <<2], Val[n <<2], Next[n <<2], CNT, out[N], vis[n];4 DoubleF[n];5 voidAddintXintYintz)6 {7TO[++CNT] =y;8VAL[CNT] =Z;9NEXT[CNT] =Head[x];TenHEAD[X] =CNT; One } A voidDfsintx) - { -     if(Vis[x]) the         return; -VIS[X] =1; -     inti; -      for(i = head[x]; i; i =Next[i]) +     { - DFS (To[i]); +F[X] + = F[to[i]] +Val[i]; A     } at     if( out[x]) -F[X]/= out[x]; - } - intMain () - { -     intN, m, x, Y, Z; inscanf"%d%d", &n, &m); -      while(M-- ) to     { +scanf"%d%d%d", &x, &y, &z); - Add (x, y, z); the          out[x] + + ; *     } $Dfs1);Panax Notoginsengprintf"%.2lf\n", f[1]); -     return 0; the}

The end of "bzoj3036" 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.