求期望的题目(~~~water~~~)

压了下代码,压成15行hhh;

我把代码压成这么丑估计也没有人看吧;

毕竟是zky讲的一个水题,就当给博客除草了;

#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#define ll long long;
using namespace std;
struct node{int nxt,to,v;}E[200003];
bool vis[100003];double f[100003];int cnt=1,N,M,point[100003],chu[100003];
int getint(){char c;while (!isdigit(c=getchar()));int a=c-'0';while (isdigit(c=getchar()))a=a*10+c-'0';return a;}
void insect(int a,int b,int c){E[cnt].nxt=point[a];point[a]=cnt;E[cnt].to=b;E[cnt].v=c;cnt++;}
void dfs(int x){if (vis[x]) return; vis[x]=1;
for (int i=point[x];i;i=E[i].nxt){dfs(E[i].to);f[x]+=E[i].v+f[E[i].to];}
if (chu[x]!=0) f[x]=f[x]*1.0/chu[x];}
int main(){N=getint(); M=getint(); memset(chu,0,sizeof(0));memset(point,0,sizeof(0)); memset(f,0,sizeof(f)); memset(vis,0,sizeof(vis));
while (M){M--;int a=getint(),b=getint(),c=getint();insect(a,b,c);chu[a]++;}dfs(1);printf("%.2lf\n",f[1]);return 0;}
05-11 13:02