标签:
4 4
1 2 1
1 3 2
2 3 3
3 4 4
7.00
1 #include<algorithm> 2 #include<cstdio> 3 #include<cstring> 4 #include<iostream> 5 #include<vector> 6 #include<queue> 7 using namespace std; 8 const int mxn=120000; 9 vector<int>e[mxn]; 10 vector<int>len[mxn]; 11 queue<int>q; 12 int out[mxn],deg[mxn]; 13 double f[mxn]; 14 int n,m; 15 16 int main(){ 17 cin>>n>>m; 18 int i,j; 19 int a,b,c; 20 for(i=1;i<=m;i++){ 21 scanf("%d %d %d",&a,&b,&c); 22 e[b].push_back(a);//入边 23 len[b].push_back(c);//边长 24 out[a]++; 25 } 26 for(i=1;i<=n;i++)deg[i]=out[i];//备份 27 q.push(n); 28 while(!q.empty()){ 29 int v=q.front(),u,le; 30 q.pop(); 31 for(i=0;i<e[v].size();i++){ 32 u=e[v][i];le=len[v][i]; 33 f[u]+=(f[v]+le)/out[u]; 34 deg[u]--; 35 if(!deg[u]) q.push(u); 36 } 37 } 38 printf("%.2lf",f[1]); 39 return 0; 40 }
标签:
原文地址:http://www.cnblogs.com/SilverNebula/p/5634373.html