fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define pb push_back
  4. #define mp make_pair
  5. #define timesaver ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. const unsigned int mod=1e7+7;
  7. #define PI 3.14159265
  8. typedef long long int ll;
  9. const long long int N=1e5;
  10. float a[200009];
  11. vector <ll> v[200009];
  12. bool visit[200009]={false};
  13. ll ve=0,e=0;
  14.  
  15. void dfs(ll x)
  16. {
  17. float s=0;
  18. visit[x]=true;
  19. for(int i=0;i<v[x].size();i++)
  20. {
  21. if(visit[v[x][i]]==false)
  22. dfs(v[x][i]);
  23. }
  24. if(v[x].size()==1)
  25. a[x]=0;
  26. else if(x!=1)
  27. {
  28. s=0;
  29. for(int j=0;j<v[x].size();j++)
  30. {
  31. s=s+a[v[x][j]];
  32. }
  33. a[x]=(s/(v[x].size()-1))+1;
  34. }
  35. return ;
  36. }
  37.  
  38. int main() {
  39. timesaver;
  40. float t=0.0,ans;
  41. ll m,d,l,k,n,q=0,p=0,z=0,w,pre=1e5,mid,co[5]={0},ab[100009]={0},b[10009]={0},t1,t2,now,r=0,i=0,j=0,flag=0,temp=0,e=-1e4,o=0;
  42. cin>>n;
  43. for(i=0;i<n;i++)
  44. {
  45. cin>>p>>q;
  46. v[p].pb(q);
  47. //v[q].pb(p);
  48. }
  49. dfs(1);
  50. for(i=0;i<v[1].size();i++)
  51. {
  52. t=t+a[v[1][i]];
  53. }
  54. ans=(t/v[1].size())+1;
  55. cout<<ans;
  56. return 0;
  57. }
Success #stdin #stdout 0s 7852KB
stdin
4
1 2
1 3
2 4
stdout
3