Background with the new version of Baidu space on-line, blog pet mung Bean Frog completed its mission, to find its new destination. The description gives a direction-free graph with a starting point of 1 ending at N, each edge 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? Input format 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 per line, representing the expected value from a to B with a forward-side output format of length C from the beginning to the end path total length, rounded to retain two decimal places. Test Sample 1 input
4 4
1 2 1
1 3 2
2 3 3
3 4 4
Output
7.00
Note for 20% of data n<=100
For 40% of data n<=1000
For 60% of data n<=10000
For 100% data n<=100000,m<=2*n topology + dynamic test data are tested locally, but when submitted full output 0, visual is not sure why the data is not read into. Strange, not resolved.
1#include <algorithm>2#include <cstdio>3#include <cstring>4#include <iostream>5#include <vector>6#include <queue>7 using namespacestd;8 Const intmxn=120000;9vector<int>E[MXN];Tenvector<int>LEN[MXN]; Onequeue<int>Q; A int out[MXN],DEG[MXN]; - DoubleF[MXN]; - intn,m; the - intMain () { -Cin>>n>>m; - inti,j; + inta,b,c; - for(i=1; i<=m;i++){ +scanf" %d%d%d",&a,&b,&c); AE[b].push_back (a);//into the side atLen[b].push_back (c);//Edge Length - out[a]++; - } - for(i=1; i<=n;i++) deg[i]= out[i];//Backup - Q.push (n); - while(!Q.empty ()) { in intv=Q.front (), U,le; - Q.pop (); to for(i=0; I<e[v].size (); i++){ +u=e[v][i];le=Len[v][i]; -f[u]+= (F[v]+le)/ out[u]; thedeg[u]--; * if(!Deg[u]) q.push (u); $ }Panax Notoginseng } -printf"%.2LF", f[1]); the return 0; +}
The TYVJP1933 of mung bean frog