-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode839C.cpp
More file actions
46 lines (34 loc) · 807 Bytes
/
Copy pathcode839C.cpp
File metadata and controls
46 lines (34 loc) · 807 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
/*
* Contest : Codeforces
* Problem : 839C - Journey
* Link : https://codeforces.com/contest/839/problem/C
*/
#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
typedef long double ld;
vector<vector<int>> graph;
vector<bool> visited;
ld dfs(int no) {
visited[no] = true;
if (graph[no].size() == 1) return 0.;
ld sum = 0.;
for (auto &v : graph[no]) {
if (!visited[v]) sum += dfs(v) + 1;
}
return sum / (graph[no].size() - (no != 1));
}
int main() {
fastio
int n; cin >> n;
graph.resize(n + 1);
visited.assign(n + 1, false);
for (int i = 0; i < n - 1; ++i) {
int a, b;
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
cout << fixed << setprecision(7) << dfs(1) << '\n';
return 0;
}