bzoj 3036: 绿豆蛙的归宿
23333sb题都做不对,,,感觉傻傻哒。。。23333333333333,一开始简直是直接真·乱搞啊。。
1 #include <bits/stdc++.h> 2 #define LL long long 3 #define lowbit(x) x&(-x) 4 #define inf 0x3f3f3f3f 5 using namespace std; 6 inline int ra() 7 { 8 int x=0,f=1; char ch=getchar(); 9 while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();} 10 while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();} 11 return x*f; 12 } 13 int n,cnt,m; 14 int head[100005],d[100005],in[100005]; 15 double f[100005]; 16 bool vis[100005]; 17 struct edge{ 18 int to,next,v; 19 }e[200005]; 20 void insert(int x, int y, int v) 21 { 22 e[++cnt].next=head[x]; e[cnt].to=y; e[cnt].v=v; head[x]=cnt; d[x]++; 23 } 24 void dfs(int x) 25 { 26 if (!vis[x]) vis[x]=1; else return; 27 for (int i=head[x];i;i=e[i].next) 28 { 29 dfs(e[i].to); 30 f[x]+=(double)(f[e[i].to]+e[i].v)/(double)d[x]; 31 } 32 } 33 int main(int argc, char const *argv[]) 34 { 35 n=ra(); m=ra(); 36 for (int i=1; i<=m; i++) 37 { 38 int x=ra(),y=ra(),v=ra(); 39 insert(x,y,v); 40 } 41 dfs(1); 42 printf("%.2lf\n",f[1]); 43 return 0; 44 }