标签:
4 4
1 2 1
1 3 2
2 3 3
3 4 4
7.00
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 #include<queue> 7 #include<cstdlib> 8 #include<iomanip> 9 #include<cassert> 10 #include<climits> 11 #define maxn 10001 12 #define F(i,j,k) for(int i=j;i<=k;i++) 13 #define M(a,b) memset(a,b,sizeof(a)) 14 #define FF(i,j,k) for(int i=j;i>=k;i--) 15 #define inf 0x7fffffff 16 using namespace std; 17 int read(){ 18 int x=0,f=1;char ch=getchar(); 19 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} 20 while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} 21 return x*f; 22 } 23 struct edge{ 24 int to,w,next; 25 }p[200010]; 26 int tot,n; 27 int head[100010]; 28 void addedge(int a,int b,int c){ 29 p[tot].to=b; 30 p[tot].w=c; 31 p[tot].next=head[a]; 32 head[a]=tot++; 33 } 34 double dp[100010]; 35 int out[100010],q[100010]; 36 int out1[100010]; 37 int main() 38 { 39 std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y; 40 // freopen("data.in","r",stdin); 41 // freopen("data.out","w",stdout); 42 int m,a,b,c; 43 cin>>n>>m; 44 M(head,-1); 45 while(m--){ 46 cin>>a>>b>>c; 47 addedge(b,a,c); 48 out[a]=++out1[a]; 49 } 50 int s=0,e=-1; 51 q[++e]=n; 52 while(s<=e){ 53 s++; 54 int u=q[s]; 55 for(int i=head[u];i!=-1;i=p[i].next){ 56 int v=p[i].to; 57 dp[v]+=(dp[u]+p[i].w)/out[v]; 58 if(--out1[v]==0) q[++e]=v; 59 } 60 } 61 cout<<setiosflags(ios::fixed)<<setprecision(2)<<dp[1]; 62 cout<<endl; 63 return 0; 64 }
标签:
原文地址:http://www.cnblogs.com/SBSOI/p/5634568.html