-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path839C.cpp
More file actions
50 lines (39 loc) · 954 Bytes
/
839C.cpp
File metadata and controls
50 lines (39 loc) · 954 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>
using namespace std;
vector <int> grafo[200000];
bool passou[200000];
int dis[200000];
double prob[200000];
void bfs(int root){
queue <int> fila;fila.push(root);passou[root]=true;prob[root]=1;
while(!fila.empty()){
int v = fila.front();fila.pop();
double div = 0;
for(int i=0;i<grafo[v].size();i++){
if(!passou[grafo[v][i]]) div++;
}
for(int i=0;i<(int)grafo[v].size();i++){
int adj = grafo[v][i];
if(!passou[adj]){
passou[adj] = true;
dis[adj] = dis[v]+1;
prob[adj] = prob[v]*(1.0/div);
fila.push(adj);
}
}
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;cin >> n;
for(int i=0;i<n-1;i++){
int a,b;cin >> a >> b;
grafo[a].push_back(b);grafo[b].push_back(a);
}
bfs(1);
double ev = 0;
for(int i=2;i<=n;i++) if(grafo[i].size() < 2) ev += prob[i]*(double)dis[i];
printf("%.10lf\n",ev);
return 0;
}