File tree 2 files changed +44
-0
lines changed
2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ Idea:
3
+ - DFS and calculate the answer.
4
+ */
5
+
6
+ #include < bits/stdc++.h>
7
+
8
+ using namespace std ;
9
+
10
+ int const N = 1e5 + 1 ;
11
+ bool vis[N];
12
+ int n;
13
+ vector<vector<int > > g;
14
+
15
+ double rec (int u, int p) {
16
+ vis[u] = true ;
17
+
18
+ double ret = 0 , prop = 1.0 / (g[u].size () - (p != -1 ));
19
+ for (int i = 0 , v; i < g[u].size (); ++i) {
20
+ v = g[u][i];
21
+
22
+ if (!vis[v])
23
+ ret += (rec (v, u) + 1 ) * prop;
24
+ }
25
+
26
+ return ret;
27
+ }
28
+
29
+ int main () {
30
+ scanf (" %d" , &n);
31
+ g.resize (n);
32
+ for (int i = 0 , a, b; i < n - 1 ; ++i) {
33
+ scanf (" %d %d" , &a, &b);
34
+ --a, --b;
35
+ g[a].push_back (b);
36
+ swap (a, b);
37
+ g[a].push_back (b);
38
+ }
39
+
40
+ printf (" %.10lf\n " , rec (0 , -1 ));
41
+
42
+ return 0 ;
43
+ }
Original file line number Diff line number Diff line change 378
378
- [ 837A. Text Volume] ( http://codeforces.com/contest/837/problem/A )
379
379
- [ 837B. Flag of Berland] ( http://codeforces.com/contest/837/problem/B )
380
380
- [ 837C. Two Seals] ( http://codeforces.com/contest/837/problem/C )
381
+ - [ 839C. Journey] ( http://codeforces.com/contest/839/problem/C )
381
382
- [ 842A. Kirill And The Game] ( http://codeforces.com/contest/842/problem/A )
382
383
- [ 842B. Gleb And Pizza] ( http://codeforces.com/contest/842/problem/B )
383
384
- [ 845A. Chess Tourney] ( http://codeforces.com/contest/845/problem/A )
You can’t perform that action at this time.
0 commit comments